Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js - `npm run build` failed

Trying to build my app with target: 'serverless' in next.config.js (In-order to deploy on AWS Lambda). When running npm run build I'm getting the following output:

Warning: Built-in CSS support is being disabled due to custom CSS configuration being detected.
See here for more info: https://err.sh/next.js/built-in-css-disabled  

info  - Using external babel configuration from C:\Users\User\Desktop\mysite\.babelrc
info  - Creating an optimized production build  
warn  - Compiled with warnings

./node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression     

./node_modules/node-pre-gyp/lib/pre-binding.js
Critical dependency: the request of a dependency is an expression     

./node_modules/node-pre-gyp/lib/util/versioning.js
Critical dependency: the request of a dependency is an expression     

./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in 'C:\Users\User\Desktop\mysite\node_modules\node-fetch\lib'

./node_modules/mongodb/lib/operations/connect.js
Module not found: Can't resolve 'mongodb-client-encryption' in 'C:\Users\User\Desktop\mysite\node_modules\mongodb\lib\operations'

./node_modules/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'node-gyp' in 'C:\Users\User\Desktop\mysite\node_modules\node-pre-gyp\lib\util'

./node_modules/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'npm' in 'C:\Users\User\Desktop\mysite\node_modules\node-pre-gyp\lib\util'

./node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html 1:0        
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>


> Build error occurred
Error: package.json does not exist at C:\package.json
    at Object.module.exports.wr/F.exports.find (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:188263:15)
    at Object.<anonymous> (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:154078:28)
    at Object.paWE (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:154141:30)
    at __webpack_require__ (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:23:31)
    at Object.xDbK (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:189175:64)
    at __webpack_require__ (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:23:31)
    at Object.gL7F (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:123042:67)
    at __webpack_require__ (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:23:31)
    at Module.IlR1 (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:53618:12)
    at __webpack_require__ (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:23:31)
    at Module.ScIc (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:81256:17)
    at __webpack_require__ (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:23:31)
    at C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:91:18
    at Object.<anonymous> (C:\Users\User\Desktop\mysite\.next\serverless\pages\_error.js:94:10)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)       
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
info  - Collecting page data .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!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2020-09-12T19_38_11_418Z-debug.log

What is the meaning of this error?

Error: package.json does not exist at C:\package.json

And what about all the Module not found: Can't resolve errors?

EDIT:
I have package.json in project folder.
when I run npm run dev it works just fine.
I don't know why he is complaining about C:\package.json
(the project is not under C:\, but C:\Users\User\Desktop\mysite)

like image 366
user3343396 Avatar asked Sep 14 '20 07:09

user3343396


People also ask

Is there a problem with npm err?

npm ERR! This is probably not a problem with npm. Probably don`t depend from Npm or nodejs. I supppose some modules are missing in this folder:

How do I deploy nextnext's Node JS application?

Next.js can be deployed to any hosting provider that supports Node.js. For example, AWS EC2 or a DigitalOcean Droplet. First, ensure your package.json has the "build" and "start" scripts: Then, run next build to build your application. Finally, run next start to start the Node.js server.

How to build a NPM project from a packege?

First, in the packege.json file, in the section scripts, we must modify the property “build”: "next build && next export", and a new property "export": "next export" Second, we must establish the component and data folders in the root of the project Third: use the command: npm dev build Tha give to you and folder with the name "out"

What is the fastest way to deploy my next JS application?

It's the fastest way to deploy your managed Next.js application with zero configuration. When deploying to Vercel, the platform automatically detects Next.js, runs next build, and optimizes the build output for you, including: In addition, Vercel provides features like: Automatic CI/CD (through GitHub, GitLab, Bitbucket, etc.)


1 Answers

When you npm run it will run whatever it is inside the script section of package.json in the directory but for some reason, it is invoked in here. I think there are 2 possibilities.

1/Either your current package.json somehow looks for C:\package.json and the error occurs

2/Your npm cache is including the C:\package.json for some reason try npm cache clean or npm cache clean --force

like image 156
Chass Long Avatar answered Sep 19 '22 06:09

Chass Long