Home > Net >  next.js - how to fix issue with npm run build
next.js - how to fix issue with npm run build

Time:12-31

I have a project on a test server which I am able to deploy successfully with npm run build

Now I am trying to deploy it on the production server but I am getting the following error:

/home/clients/7cb14b18a04cde30fa48b73997f5d66d/sites/americanmarket.ch/node_modules/next/dist/telemetry/storage.js:101
    notify = ()=>{
           ^

SyntaxError: Unexpected token =
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787: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:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/clients/7cb14b18a04cde30fa48b73997f5d66d/sites/americanmarket.ch/node_modules/next/dist/build/index.js:37:16)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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!     /home/clients/7cb14b18a04cde30fa48b73997f5d66d/.npm/_logs/2022-12-29T10_34_13_423Z-debug.log

What I tried to do to fix the issue was to check the versions for packages like next, react and react-dom on the test server and use the exact same versions in the package.json for the prod server. I deleted the node_modules folder and package-lock.json file I tried an npm install and npm run build again but I still got the same error.

At this point I'm not too sure how I can fix this issue.

CodePudding user response:

Hi @Jolan,

It is hard to tell you what cause this error message. But, There are a few things.

  • It's possible If you are using a version of Node.js that is older than the version that you used on the test server, certain features of your code that are supported in newer versions of Node.js may not work in the older version. This could cause syntax errors or other issues when you try to run your code. First, try to run this command and see if Babel able to transpile your code successfully, babel src --out-dir build. Then check node version by run that node -v.

  • Most of the time I see the issue could be related to Babel, which is a JavaScript transpiler that allows you to use newer JavaScript syntax in older environments. If you are using Babel in your project, and you are seeing syntax errors like Unexpected token =, it could be because Babel is not correctly transpiling your code.

  • Maybe you need to clear the NPM cache and then run NPM install again.

npm cache clean --force.

If you are still unable to resolve the issue, then, you need to check the logs for more infomation.

  • As Mr.@Canberk Sahin described.

Can you check the debug log from here /home/clients/7cb14b18a04cde30fa48b73997f5d66d/.npm/_logs/2022-12-29T10_34_13_423Z-debug.log

  • Related