[WebPack2]when use import() in code, get a error: Module build failed: ReferenceError: ……/src/main.js: unknown node of type “Import” with constructor “Node”

This is a demo repository: https://github.com/XuJinNet/webpack-test

Code
main.js

import('./b')
	.then(b => {
		b.default.test();
	});

class A {
	constructor() {

	}

	func1() {
		console.log('money 💰😊');
	}
}

const a = new A();
a.func1();

b.js

export default {
	test() {
		console.log('OK 👌 ☀️ 😊 ❤️');
	}
};

.babelrc

......
"plugins": [
		"syntax-flow",
		"transform-decorators-legacy",
		"transform-flow-strip-types",
		"transform-class-properties",
		"transform-function-bind",
    	"syntax-dynamic-import"
      ]
......

The error:

./src/main.js
Module build failed: ReferenceError: /Users/xujin/My_Projects/NodeJS/test/webpack-test/src/main.js: unknown node of type "Import" with constructor "Node"
    at Generator.print (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:279:13)
    at Generator.CallExpression (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/generators/expressions.js:122:8)
    at /Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:298:23
    at Buffer.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/buffer.js:151:5)
    at Generator.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:189:15)
    at Generator.print (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:297:10)
    at Generator.MemberExpression (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/generators/expressions.js:215:8)
    at /Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:298:23
    at Buffer.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/buffer.js:151:5)
    at Generator.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:189:15)
    at Generator.print (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:297:10)
    at Generator.CallExpression (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/generators/expressions.js:122:8)
    at /Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:298:23
    at Buffer.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/buffer.js:151:5)
    at Generator.withSource (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:189:15)
    at Generator.print (/Users/xujin/My_Projects/NodeJS/test/webpack-test/node_modules/babel-generator/lib/printer.js:297:10)
 @ multi (webpack)-dev-server/client?http://0.0.0.0:9000 ./src/main.js

webpack: 2.2.0
webpack-dev-server: 2.2.0
Browser: All
Node: 6.9.4
OS: macOS 10.12.2

Author: Fantashit

1 thought on “[WebPack2]when use import() in code, get a error: Module build failed: ReferenceError: ……/src/main.js: unknown node of type “Import” with constructor “Node”

  1. Yes probably out of date babel-generator since you yourself made the PR 😄. Just make sure all deps are up to date.

Comments are closed.