debugger not recognizing es6 server side

Application works fine with the config in npm start run from terminal. My debugger configurations is set to running npm and command start, i have set the local package.json correctly and it's using the correct node version. However, the app crashes because it doesn't recognize ES6 syntax?

In config for project javascript version is set to ES6. I have webstorm 2017.2

 

.get((...args) => controller.find(...args))
^^^

SyntaxError: Unexpected token ...

 

1
7 comments

Please attach screenshots of your run configuration and run console with the error (make sure that the command used to run the app is visible in run console screenshot)

1
Avatar
Permanently deleted user

Thanks for helping out, screenshot attached!

1

Ok. What does your start script look like?

If it works in terminal, it should work just in the same way when being started from WebStorm (unless it relies on some specific environment variables only available in terminal environment): all WebStorm does is starting the chosen Node.js interpreter and passing the specified script to it, nothing more

1
Avatar
Permanently deleted user

I'm having exactly the same problem in an es6 nodejs project in intellij IDEA ultimate 2020.1

I can start the sample app from the terminal "npm start", but any method that uses the ide fails with the same errors describe by the OP.

if I use babel it works, if I write it in es5 it works.

 

0

What does your start script look like? What run configurations do you use to run your code from the IDE? Please share screenshots illustrating the issue

 

0
Avatar
Permanently deleted user

I think I have found the issue but I don't know how to fix it. The incorrect Node Version is being used by intellij.

I changed the start script to include the node version as follows

"start": "node -v && node src/server.mjs",

the output shows the following...

/home/mydev/.nvm/versions/node/v15.4.0/bin/node /home/mydev/.nvm/versions/node/v15.4.0/lib/node_modules/npm/bin/npm-cli.js run startDirect --scripts-prepend-node-path=auto
Debugger listening on ws://127.0.0.1:44967/4a9b77e6-ce83-4e22-b785-c5a6ab14e05b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

> node-demo@1.0.0 startDirect
> node -v && node src/server.mjs

v10.24.0
Debugger listening on ws://127.0.0.1:45051/1a021947-8655-4c2d-a45d-7bfccefbc4ca
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
/home/mydev/IdeaProjects/nodejs-express-es6/src/server.mjs:2
import express from 'express';
^^^^^^^

SyntaxError: Unexpected identifier

What is strange is the node version I am setting in the run configuration is different from the version that is printed.

The default interpreter is set to v15.4.0

The debug configuration shows the same...

and yet when I check the version of node during the start script is shows Node 10

 

0

It's strange... According to the docs (https://docs.npmjs.com/cli/v7/commands/npm-run-script):

npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH.

But in your case the executable npm is started with (/home/mydev/.nvm/versions/node/v15.4.0/bin/node) is ignored by npm , and not added to PATH despite the option, and node is resolved from PATH to version 10. Looks like a bug that has to be reported to https://github.com/npm/npm/issues

 

 

0

Please sign in to leave a comment.