browserify / static-module

convert module usage to inline expressions
MIT License
74 stars 23 forks source link

Allow import and export statement #32

Open fabiosantoscode opened 7 years ago

fabiosantoscode commented 7 years ago

Currently, static-module crashes when reading modules which use the 'import' statement. This makes it fail to parse those modules and crash with the cryptic error message:

'import' and 'export' may appear only with 'sourceType: module' 

Which after some research I found comes from acorn, which is the crashing entity here :)

(my use case, IE how this crash affects me): This failure cascades to brfs, and from then on webpack's transform-loader. Webpack 2 now supports ES6 modules, which create-react-app favours. This made webpack fail to compile my project as it uses import statements.

fabiosantoscode commented 7 years ago

Googlers from the future:

I worked around this issue by setting the acorn options myself. Since this module doesn't use acorn directly to parse, you need to get the same acorn as the one falafel is using. Which is a bit weird with npm3.

require('falafel/node_modules/acorn').defaultOptions.sourceType = 'module'

It's quite quirky and confusing, but that will do for this prototype.

Cheers!

chengqiaozhi commented 6 years ago

@fabiosantoscode Hi, i check the falafel but got nothing for acorn, i use webpack 3.0, thanks