"Unexpected token import" when running babel-watch
See original GitHub issueHey @kmagiera
Thanks for creating this package. It seems very useful! Unfortunately I wasn’t able to make it work so far. I have used the following command:
babel-watch --presets es2015 --watch src webpack/production.js
as well as other variations like these:
babel-watch --presets "es2015" --watch src webpack/production.js
babel-watch --presets=es2015 --watch src webpack/production.js
babel-watch --presets="es2015" --watch src webpack/production.js
I am getting the following error message:
C:\repos\my_repo\webpack\production.js:1
(function (exports, require, module, __filename, __dirname) { import webpack from 'webpack';
^^^^^^
SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:404:25)
at Module._extensions..js (module.js:432:10)
at loader (C:\repos\my_repo\node_modules\babel-watch\runner.js:14:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\repos\my_repo\node_modules\babel-watch\runner.js:22:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:457:10)
at process.<anonymous> (C:\repos\my_repo\node_modules\babel-watch\runner.js:38:21)
at emitTwo (events.js:87:13)
The file in question starts like this:
import webpack from 'webpack';
I also have a .babelrc
-file but it doesn’t seem to pick it up.
Any idea how I can get it to work? I’m currently using nodemon with the following command (and yes, the performance is pretty bad):
nodemon --exec babel-node --debug webpack/production.js --watch webpack/production.js
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
"unexpected token import" in Nodejs5 and babel?
In my package.json under scripts, I forgot to replace "node run" with "babel-node run.js". Yeah, I feel sheepish. :).
Read more >[Solved]-Unexpected token import(ReactJS & Babel)-babel.js
Coding example for the question Unexpected token import(ReactJS & Babel)-babel.js. ... if you have not already added babel to dev dependencies, run.
Read more >How To Use Import Statements in Nodejs - Better Programming
One of the most common is using import statements in Nodejs files. This leads to a syntax error called Unexpected identifier . Even...
Read more >Mongodb – How to fix Error cannot find module 'core-js/es6 ...
... mongoose and babel-watch, but every time I run babel-watch I get this error: ... For core.js v3.9 import in App.tsx the next...
Read more >babel-watch - Bountysource
If specify --debug-brk then app stop running: node_modules/.bin/babel-watch src/server.js -I --debug-brk. If only --inspect option - all fine:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What am I doing wrong here?
Have
"babel-watch": "^7.0.0"
in devDependencies and"dev": "babel-watch --presets es2015 ./index.js",
in scripts of package.json, have an index.js withimport express from "express";
but runningyarn dev
gives me:I ran into the same issue as @harm-meijer and it turned out to be caused by having a space in my path. Changing the directory let me run things as usual