Launching command through Webstorm run configurations leads to errors
I have a NextJS project with the following script in `package.json`
"scripts": {
"dev": "nodemon -w server.js -w package.json -w next.config.js -w server",
// ...
}
When I launch this command via typing `npm run dev` in the terminal, everything works just fine. Unfortunately, when I add wWebstorm run configuration that launches the `dev` script and run it, I get the following error:
Module parse failed: Unexpected token (21:12)
You may need an appropriate loader to handle this file type.
|
| return (
> <Container>
| <Head>
It's not my code or configuration that breaks it: I tried explicitly setting babel to use @babel/react preset, but it didn't help. What may cause it?
Please sign in to leave a comment.
strange... looks as if the appropriate configuration files (.babelrc, etc) are not found. But running npm through the run configuration works in exactly same way as when running it in terminal - it runs node path/to/npm-cli.js run dev in a folder where the package.json file is located. Do you create a run configuration manually, or start the script from a gutter in package.json file?
Actually it does find babel configuration. Generally NextJS takes care of it, but when I explicitly set it creating babel.config.js, before crashing it writes
I'm really confused about it, because I tried copying the exact same command that Webstorm ran in "Run" panel (O:\Programs\NodeJS\node.exe O:\Programs\NodeJS\node_modules\npm\bin\npm-cli.js run dev --scripts-prepend-node-path=auto) and launching it in "Terminal" and it worked just fine. By the way, through terminal it works in any cases (npm run, node server, nodemon server, next dev) and with webstorm it doesn't work neither when I use my own configuration nor when I launch it in gutter.
I had the same issue with another project, then the thing that helped me was deleting folder and copying it from git again. In this case I tried to reinstall webstorm, delete and restore project, reinstalling node_modules, invalidating cache but it still doesn't work
>I had the same issue with another project, then the thing that helped me was deleting folder and copying it from git again. In this case I tried to reinstall webstorm, delete and restore project, reinstalling node_modules, invalidating cache but it still doesn't work
it doesn't look related to IDE settings, so re-installing/starting with fresh configs won't help. It looks like a weird problem with your setup that isn't directly related to the IDE.
The problem like yours may occur if your launch configuration relies on certain things only available in terminal environment (environment variables, shell commands/scripts, etc). You also need to check twice if the working directory is the same in terminal and in the IDE
It didn't actually rely on any of such things. And the working directory was the same. Nevertheless, fortunately, this problem disappeared, when I deleted my .Webstorm folder and configured everything again, thank you anyways