Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

SyntaxError: Unexpected token import #542

Open
liketurbo opened this issue Mar 15, 2018 · 1 comment
Open

SyntaxError: Unexpected token import #542

liketurbo opened this issue Mar 15, 2018 · 1 comment

Comments

@liketurbo
Copy link

liketurbo commented Mar 15, 2018

SyntaxError: Unexpected token import, despite that I use babel.

import path from 'path';
import { System } from 'es-module-loader/core/loader-polyfill';

export default class HelloWorld {
  constructor(options) {
    this.options = options;
  }

  apply(compiler) {
    compiler.plugin('done', () => {
      this.done();
    });
  }

  done() {
    System.import(path.resolve('central.consts.js'))
      .then(m => console.log(m));
  }
}  

package.json script

"webpack:dev": "babel-node ./node_modules/.bin/webpack-cli --mode=development"

webpack.config.js

import path from 'path';

import HtmlWebpackPlugin from 'html-webpack-plugin';
import CentralConstsPlugin from './src/plugins/central-consts-plugin';

const basic = {
  entry: {
    app: './src/scripts/main.js',
  },
  output: {
    path: path.join(__dirname, 'build'),
    filename: '[name].js',
  },
};

const module = {
  rules: [
    {
      test: /\.js$/,
      use: ['babel-loader'],
    },
  ],
};

const plugins = [
  new CentralConstsPlugin(),
  new HtmlWebpackPlugin({
    template: path.join(__dirname, 'src/index.html'),
  }),
];

export default {
  ...basic,
  plugins,
  module,
};

@Tammy-Liu
Copy link

I got the same problem, did you solved it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants