The token '&&' is not a valid statement separator in this version

谁都会走 提交于 2021-01-27 18:30:05

问题


On the way of installing Webpack on my React Project, the following problem hinders my progress:

last step to configure the Webpack

npm run build && node ./dist/main.js

Error on Windows Power Shell / on Visual Studio Code

PS C:\Users\pythonbuddha\Desktop\to_experiment\to-do-list> npm run build && node ./dist/main.js
At line:1 char:15
+ npm run build && node ./dist/main.js
+               ~~
The token '&&' is not a valid statement separator in this version.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine

Tutorial which promised to configure the webpack

https://developerhandbook.com/webpack/webpack-4-from-absolute-scratch/

https://developerhandbook.com/webpack/how-to-configure-scss-modules-for-webpack/

回答1:


It's because you're in PowerShell, try running it in CMD or Git Bash

Alternatively (if you wish to continue in PS):

(npm run build) -and (node ./dist/main.js)

3rd Alternative, just run them separetly,




回答2:


The && operator is used in linux bash to run both commands after each other. (Also if the first command fails, the second won't be executed)

This does not work in PowerShell on Windows so just split both commands and run them separately:

npm run build
node ./dist/main.js

For completeness, Powershell can behave the same when you do (command1) -and (command2) and && might actually work depending on your PowerShell version.

See this for further info: https://stackoverflow.com/a/564092/2232127




回答3:


simply run the two commands separately:

npm run build
node ./dist/main.js


来源:https://stackoverflow.com/questions/65627536/the-token-is-not-a-valid-statement-separator-in-this-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!