babelify: ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Hello,
I updated babelify to 7.0.2 and now it throws this error:
Browserify Error
/Applications/MAMP/htdocs/folder-name/assets/js/main.js:1
import framework from './framework';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Working with 6.4.0. Do you maybe have any ideas?
Thanks!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 8
- Comments: 17 (3 by maintainers)
You upgraded to babelify 7.0, which uses the new babel 6.0, and you’re missing options. Please read the README.
This is what I needed to do to fix this error:
npm install --save-dev babel-preset-es2015
gulpfile.js
:package.json
:https://github.com/babel/babelify#options
Totally appreciate the help @zertosh.
If people open new issues with their current configurations and what features they want, I’d be more than happy to tell them what’s missing. I don’t know how else to help.
MFW people say RTFM and they think they are helping just because some people randomly solve their problems alone after they read the insult.
I too am seeing this problem after updating to Babel 6. @zertosh you have said See README in several answers to this, but yet I cant find anything in the README that specifically states which options we need to provide to avoid this issue. Can you update the README there and put something like NOTE: If you are seeing this error (…) this is why and here is how to solve it. All the searches I am seeing on google indicate some option is not sent to Babel 6, yet at least from what I have found so far, my webpack includes the es2015, react and state-1/23 options in the loader section of my webpack. I am also including all the correct dependencies in my package.json file. So any pointers to what we need to do would be of HUGE help to many of us that have this problem. Also, what README are you referring to? I looked through the page about migrating from Babel 5 to Babel 6… maybe I am looking at the wrong README?
For browserify users that are running into this issue:
• It is likely that this issue is getting triggered because you’re importing
node_modules
that are not being babelified. • What? Yes, by default,node_modules
are not babelified. • Solve by passingglobal
as an option to the babelify transform plugin My example from package.json:• I also converted my
.babelrc
to ababel.config.js
file, as suggested when you are using a monorepo or want to compile files from node_modules.Hope it helps someone!
(Commenting here since this issue is one of the top results for the query)
@baptistebriel: I think you can use either the browserify config in package.json or pass the config in the browserify transform. I don’t think you don’t need both (at least I didn’t).
es2016
only processes the things added in ES2016, just likees2015
is only the things added in ES2015, so you’d either want to use both, or use something likebabel-preset-latest
.If you are using react-native, I’ve got this error after init a new project and it was due to the defaults included packages (maybe
"babel-eslint": "^7.0.0"
not sure).I’ve finally removed my
.babelrc
config file to add a.eslintrc
with all my linter config and solve my problem Eslintrc example config here --> https://gist.github.com/ansmonjol/7e8131c3bb61609c22b98bb1ee218bbbThanks for this @baptistebriel I updated and have been having this issue all night!