Home
Support Forums

Build Next JS TypeScript error - build failed

Hello, i’m facing to this issue and i don’t understand what’s wrong, Please someone can help me ?
Please, find bellow my full Deploy log

────────────────────────────────────────────────────────────────
10:11:42 AM: ​
10:11:42 AM: $ yarn build
10:11:42 AM: yarn run v1.22.10
10:11:42 AM: $ next build
10:11:43 AM: info - Using webpack 5. Reason: Enabled by default webpack5 | Next.js
10:11:43 AM: info - Checking validity of types…
10:11:48 AM: warn - No ESLint configuration detected. Run next lint to begin setup
10:11:48 AM: info - Creating an optimized production build…
10:11:55 AM: warn - You have enabled the JIT engine which is currently in preview.
10:11:55 AM: warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
10:12:15 AM: (node:1928) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
10:12:15 AM: (Use node --trace-deprecation ... to show where the warning was created)
10:12:23 AM: Failed to compile.
10:12:23 AM:
10:12:23 AM: ./node_modules/node-gyp/lib/Find-VS2017.cs
10:12:23 AM: Module parse failed: Unexpected token (7:6)
10:12:23 AM: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See Concepts | webpack
10:12:23 AM: | // Usage:
10:12:23 AM: | // powershell -ExecutionPolicy Unrestricted -Version “2.0” -Command “&{Add-Type -Path Find-VS2017.cs; [VisualStudioConfiguration.Main]::Query()}”
10:12:23 AM: > using System;
10:12:23 AM: | using System.Text;
10:12:23 AM: | using System.Runtime.InteropServices;
10:12:23 AM: > Build error occurred
10:12:23 AM: Error: > Build failed because of webpack errors
10:12:23 AM: at /opt/build/repo/node_modules/next/dist/build/index.js:397:19
10:12:23 AM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:60:20)
10:12:23 AM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:77:25)
10:12:23 AM: error Command failed with exit code 1.
10:12:23 AM: info Visit yarn run | Yarn for documentation about this command.
10:12:23 AM: ​
10:12:23 AM: ────────────────────────────────────────────────────────────────
10:12:23 AM: “build.command” failed
10:12:23 AM: ────────────────────────────────────────────────────────────────
10:12:23 AM: ​
10:12:23 AM: Error message
10:12:23 AM: Command failed with exit code 1: yarn build
10:12:23 AM: ​
10:12:23 AM: Error location
10:12:23 AM: In Build command from Netlify app:
10:12:23 AM: yarn build
10:12:23 AM: ​
10:12:23 AM: Resolved config
10:12:23 AM: build:
10:12:23 AM: command: yarn build
10:12:23 AM: commandOrigin: ui
10:12:23 AM: publish: /opt/build/repo/out
10:12:23 AM: publishOrigin: ui
10:12:23 AM: plugins:
10:12:23 AM: - inputs: {}
10:12:23 AM: origin: ui
10:12:23 AM: package: ‘@netlify/plugin-nextjs’
10:12:24 AM: Caching artifacts
10:12:24 AM: Started saving node modules
10:12:24 AM: Finished saving node modules
10:12:24 AM: Started saving build plugins
10:12:24 AM: Finished saving build plugins
10:12:24 AM: Started saving yarn cache
10:12:30 AM: Finished saving yarn cache
10:12:30 AM: Started saving pip cache
10:12:30 AM: Finished saving pip cache
10:12:30 AM: Started saving emacs cask dependencies
10:12:30 AM: Finished saving emacs cask dependencies
10:12:30 AM: Started saving maven dependencies
10:12:30 AM: Finished saving maven dependencies
10:12:30 AM: Started saving boot dependencies
10:12:30 AM: Finished saving boot dependencies
10:12:30 AM: Started saving rust rustup cache
10:12:30 AM: Finished saving rust rustup cache
10:12:30 AM: Started saving go dependencies
10:12:30 AM: Finished saving go dependencies
10:12:32 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:12:32 AM: Creating deploy upload records
10:12:32 AM: Failing build: Failed to build site
10:12:33 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
10:12:33 AM: Finished processing build request in 1m59.202469163s

Looks like node_gyp is trying to look for Visual Studio on a Ubuntu system. Maybe you are developing on Windows locally? If that’s the case, could you try removing package-lock.json and yarn.lock from your repo and try to clear cache and deploy?

Hi hrishikesh,
Thanks for your help.
I confirm that i’m developing on Windows. So, I’ve remove the yarn.lock as you adviced me.
The first issue with node_gyp has dessappear.
However , I have a new issue :
" bash: yarn: command not found " .
It’s look simple to resolve but I’m not sure how I can add this.
Please fond bellow my script :

{

“private”: true,

“scripts”: {

"dev": "node ./database-test.js && next dev",

"build": "next build",

"start": "next start"

},

“dependencies”: {

"@heroicons/react": "^1.0.4",

"@material-ui/core": "^4.11.4",

"@material-ui/icons": "^4.11.2",

"@types/react-redux": "^7.1.18",

"aws-sdk": "^2.983.0",

"bootstrap": "^5.1.0",

"material-table": "^1.69.3",

"next": "latest",

"react": "^17.0.2",

"react-bootstrap": "^2.0.0-beta.6",

"react-dom": "^17.0.2",

"react-redux": "^7.2.4",

"redux": "^4.1.1",

"redux-thunk": "^2.3.0",

"sharp": "^0.29.0",

"sqlite3": "^5.0.2"

},

“devDependencies”: {

"@types/node": "^16.7.1",

"@types/react": "^17.0.19",

"autoprefixer": "^10.2.6",

"postcss": "^8.3.5",

"sqlite": "^4.0.23",

"tailwindcss": "^2.2.4",

"typescript": "^4.3.5"

}

}

Well, the node-gyp error has (probably) not disappeared (yet) as the build didn’t reach till this stage. I had assumed this would happen, because Netlify uses yarn.lock file to determine whether to install Yarn.

Regardless, you can get around the problem by adding this environment variable mentioned here:

TL;DR: var Name: NETLIFY_USE_YARN, value: TRUE.

Thanks hrishikesh ,
I’m not sure how to do that, but now I’ve this result :
────────────────────────────────────────────────────────────────
11:30:58 AM: ​
11:30:58 AM: $ yarn build
11:30:58 AM: bash: yarn: command not found
11:30:58 AM: ​
11:30:58 AM: ────────────────────────────────────────────────────────────────
11:30:58 AM: “build.command” failed
11:30:58 AM: ────────────────────────────────────────────────────────────────
11:30:58 AM: ​
11:30:58 AM: Error message
11:30:58 AM: Command failed with exit code 127: yarn build
11:30:58 AM: ​
11:30:58 AM: Error location
11:30:58 AM: In Build command from Netlify app:
11:30:58 AM: yarn build
11:30:58 AM: ​
11:30:58 AM: Resolved config
11:30:58 AM: build:
11:30:58 AM: command: yarn build
11:30:58 AM: commandOrigin: ui
11:30:58 AM: environment:
11:30:58 AM: - NETLIFY_USE_YARN
11:30:58 AM: publish: /opt/build/repo/out
11:30:58 AM: publishOrigin: ui
11:30:58 AM: plugins:
11:30:58 AM: - inputs: {}
11:30:58 AM: origin: ui
11:30:58 AM: package: ‘@netlify/plugin-nextjs’
11:30:58 AM: Caching artifacts

Hi @LionelD,

What website is this regarding?

Hi @hrishikesh,
Here is the site on my netlify portal : modest-agnesi-a16230
And If you wan’t to check the source code, here is the repo on Github : https://github.com/ldabee/portfolio

Hi @LionelD,

I got to work it with this repo:

I made some changes to webpack config based on:

And then there was a missing module reported which I added to package.json. I have got it to work with npm, didn’t try Yarn yet, but it should work. To use Yarn, you’d have to set the environment variable in Netlify UI and not .env file.

@hrishikesh Thank you very much for your help.
I’ve finally use npm run build instead yarn and apply changes that you have done.
Now, my app is well deployed.

Thanks again to the team

1 Like