9

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\_logs2020円-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)

asked Sep 14, 2020 at 7:15
2
  • 2
    change component to "@sls-next/serverless-component" in serverless.yml Commented Sep 20, 2020 at 18:05
  • Please try checking the module import paths once again. Probably a mistake in the import path like a preceding / while specifying a module name. Commented Sep 24, 2020 at 19:10

3 Answers 3

7
+25

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

answered Sep 23, 2020 at 10:02
Sign up to request clarification or add additional context in comments.

Comments

0

I think when you read this:

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:

./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'

I suggest to write in console:

npm install encoding -g
npm install mongodb-client-encryption -g
npm install node-gyp -g
npm install npm@latest -g

and change folder into "C:\Users\User\Desktop\mysite" then type:

npm install encoding --save
npm install mongodb-client-encryption --save
npm install node-gyp --save
npm install npm@latest --save

And another thing, did you do "npm init"? To initialize your folder then edit it.

answered Sep 24, 2020 at 16:30

Comments

0

I was this error, my solution was:

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"

package.json out folder

answered Nov 9, 2021 at 15:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.