I'm working with Babelify
and Browserify. Also, I'm using ES6 style module features by node module system.
I would like to put all my own modules into node_modules/libs
.
For instance:
test.js
in node_modules/libs
export default () => {
console.log('Hello');
};
main.js
(will be compiled to bundle.js
)
import test from 'libs/test';
test();
After that, I have compiled the above codes to bundle.js
with this command:
browserify -t babelify main.js -o bundle.js
But unfortunately, I have got some error:
export default () => {
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Directory structure:
[test]
`-- node_modules
│ `-- libs
│ `-- test.js
`-- main.js
But, when own modules not in node_modules
like this:
[test]
`-- libs
│ `-- test.js
`-- main.js
Then, it works fine. How can I use the ES6 style modules with babelify
in node_modules
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…