SyntaxError: Unexpected reserved word => prettier/third-party.js - node.js

I'm pretty new to Node, npm and webpack. I'm trying to set up a Craft 3 environment with Tailwind css.
Everything worked fine out of the box, but when i run npm run dev i get the following error:
> craftcms-tailwind#1.0.0 dev /Users//sites/***/www
> gulp dev
/Users/***/sites/***/www/node_modules/prettier/third-party.js:9871
for await (const place of this.config.searchPlaces) {
^^^^^
SyntaxError: Unexpected reserved word
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/***/sites/***/www/node_modules/prettier/index.js:16551:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! craftcms-tailwind#1.0.0 dev: `gulp dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the craftcms-tailwind#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/***/.npm/_logs/2020-08-28T14_23_16_034Z-debug.log
Why is this hapening and how can i make sure i can fix this in the furure?

As described here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
This syntax :
for await (const place of this.config.searchPlaces) {
// ...
}
is available in NodeJS starting version 10.0.0

I faced same issue first I tried with upgrading node v8 --> node v10 works fine.
If you do not want to upgrade your node version you can downgrade prettier version to prettier#1.13.7 This fix is also working properly.
Downgrade prettier version:
npm i -D prettier#1.13.7
More info: https://dev.to/shivampawar/syntaxerror-unexpected-reserved-word-prettierthird-partyjs-3ph7

I had the same issue in node v8.11.2. Upgraded node to version 12.3.1 and it works fine

I know it's late but for people coming here, you can either use node v10 or downgrade prettier to v1.x.x.
If any package throws an unexpected error like this please check it's package.json on github or from node_module and look for engines
"engines": {
"node": ">=8"
},
make sure it matches your node, either change (upgrade) the node version if possible or use a different (older) package version. You can check which package version is suitable by changing the version from dropdown for this file.

Related

error when try to run npm build on react project

i'm trying to deploy my app via VPS (Ubuntu and Nginx) but this error keeps showing up, (on vs code it works fine) any idea how could i procede? thanks!
> mystery#0.1.0 build /home/react-projects/portfolio
> react-scripts build
/home/react-projects/portfolio/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110
_ending;
^
SyntaxError: Unexpected token ;
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/react-projects/portfolio/node_modules/eslint-webpack-plugin/dist/getESLint.js:9:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mystery#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mystery#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-08-23T18_10_04_282Z-debug.log
one way you can :
go to your package.json
replace "react-scripts": "..." to "react-scripts": "1.1.4",
then run npm install, after that npm build
if it didn't work try :
create a file .env at the root of the folder react folder
type SKIP_PREFLIGHT_CHECK=true inside of .env file
this command will help you in resolving this npm error.
then try to run npm build and check it should work .
notice : this command will permanently disable this preflight check
Updating node to higher version worked for me, i was using v10.22.1: nvm use --lts
i solved it installing the correct versions through NVM on my web server
https://www.freecodecamp.org/news/how-to-install-node-js-on-ubuntu-and-update-npm-to-the-latest-version/

Next.js tutorial, error running Next.js dev server (npm run dev)

I'm doing the starter Next.js tutorial and encountering an error when I try to run the Next dev server and run my app.
Here is what my package.json file contains:
{
"scripts": {
"dev": "next dev"
},
"dependencies": {
"next": "^12.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
When running npm run dev, I get the following error:
> # dev /Users/renaudj/Documents/Projects/next-app
> next dev
/Users/renaudj/Documents/Projects/next-app/node_modules/next/dist/trace/report/index.js:14
reporters = [];
^
SyntaxError: Unexpected token =
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/renaudj/.npm/_logs/2022-07-04T05_09_15_196Z-debug.log
Anyone know what I'm missing here? Thank you!
I update my node version V11.15.1 to V12.22.1 then it's solved
I update my node version V10->V16. it' work
Yes, updating your version of node will solve this issue.
Before doing this, delete the node_modules folder in your project.
Then to update node to the latest stable version, run the following command on your terminal:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
You may need to restart your terminal to see the version update which you check using:
node -v
Then reinstall your project using
npm install
Basically I have multiple versins of node.
It is possible through nvm
I switched to node 14 using the command :
node use 14.15.0

Module not found (MODULE_NOT_FOUND) on nest.js code base

I have a code base which is working perfectly fine on a Windows box on node v10.16.3 but when I try to install the same code base on a CentOS Linux box with node v.12.16.3, I get the following error. Not sure what the issue could be.
# npm start
> nest start
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module '#angular-devkit/core'
Require stack:
- /usr/local/lib/node_modules/#nestjs/cli/lib/schematics/schematic.option.js
- /usr/local/lib/node_modules/#nestjs/cli/lib/schematics/index.js
- /usr/local/lib/node_modules/#nestjs/cli/actions/generate.action.js
- /usr/local/lib/node_modules/#nestjs/cli/actions/index.js
- /usr/local/lib/node_modules/#nestjs/cli/commands/command.loader.js
- /usr/local/lib/node_modules/#nestjs/cli/commands/index.js
- /usr/local/lib/node_modules/#nestjs/cli/bin/nest.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous>
(/usr/local/lib/node_modules/#nestjs/cli/lib/schematics/schematic.option.js:3:16)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/#nestjs/cli/lib/schematics/schematic.option.js',
'/usr/local/lib/node_modules/#nestjs/cli/lib/schematics/index.js',
'/usr/local/lib/node_modules/#nestjs/cli/actions/generate.action.js',
'/usr/local/lib/node_modules/#nestjs/cli/actions/index.js',
'/usr/local/lib/node_modules/#nestjs/cli/commands/command.loader.js',
'/usr/local/lib/node_modules/#nestjs/cli/commands/index.js',
'/usr/local/lib/node_modules/#nestjs/cli/bin/nest.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1
npm ERR!
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-22T14_14_24_709Z-debug.log
Delete the dist folder and again run yarn start, npm start, yarn start:dev or npm run start:dev to rebuild the dist folder. In addition yarn prebuild or npm run prebuild does the same thing using rimraf
The problem occurs when you change a name and the tsc does not change it in dist and transpiled .js files, so it cannot find the module
I think to the best of my knowledge, nestjs or tsc does that to make the transpilation faster
Nothing else worked for me but the following did:
npm install --save-dev webpack
i'm not completely sure if there is any adverse impact to this though
most important where you started node js the dist/ or / build folder has a worng path which we import or required so for
NPM : npm install --save-dev webpack
and for yarn add webpack this one packeg will slove your problem

NPM Module triggering a "SyntaxError: Unexpected token ..."! How do I fix it?

My app was working just a short while ago until I merged the master branch. Then all of a sudden I started to get the following errors:
> #COMPANY/MY_APP#1.0.5 storybook /Users/THINKBONOBO/Workspace/MY_APP
> start-storybook -p 9001 -c .storybook
/Users/THINKBONOBO/Workspace/MY_APP/node_modules/generate-page-webpack-plugin/index.js:39
...acc,
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/THINKBONOBO/Workspace/MY_APP/node_modules/#storybook/core/dist/server/config/webpack.config.prod.js:18:57)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! #COMPANY/MY_APP#1.0.5 storybook: `start-storybook -p 9999 -c .storybook`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the #COMPANY/MY_APP#1.0.5 storybook script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
The error is from some imported public package and it seems it's written in ES6 and all of a sudden my app can't read it.
I tried clearing the cache, node_modules folder, restarting my computer, cloning to a different folder... All to no avail.
What's going on?
The way I fixed this issue was that I updated my node version.
I was running 8.1.1 and updated it with brew (I originally installed node using brew)
brew update ; brew upgrade node
it upgraded to node v 10.10.0 and I was all set.
here's an article on how to update node js on a mac:
https://bytearcher.com/articles/ways-to-get-the-latest-node.js-version-on-a-mac/

NPM broken mime-db missing

I had to reinstall Nodejs on my Macbook when I ran into an issue with npm.
No matter what I did I always got this output:
$ npm
Error: Cannot find module 'mime-db'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/node_modules/form-data/node_modules/mime-types/index.js:2:10)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'mime-db'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
I did not understand who this was happening. So I installed it one more time in hope that it would be fixed. No luck.
I did fix it after a wasting to much time. That is why I put it on here so that if anybody may walk into the same problem they solve it sooner then I did.
I used following command on node command prompt
npm install mime-db
It gave me warning: unmet dependency that it requires version 1.12 of mime-db, but it will download version 1.21 of mime-db
i ran the same command again i.e.
npm install mime-db
It solved my issue
Good Luck.
Another solution:
I was trying out something else, then I upgraded node package, downloading from node website and installing it, then i did not face this issue.
Thank you
After looking in the repo of mime-db and saw that I was missing this file in the module that was installed with the pkg. I added this file and now it works.
Good luck!
I deleted mime-db from the node_modules folder. Then I ran
npm i mime-db
That solved my problem.

Resources