Verify canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Mon Feb 27 2023 14:52:57 GMT+0100 (Central European Standard Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.19
pnpm: 7.13.6
Relevant packages:
next: 13.2.2-canary.1
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-tteixg?file=app%2Fpage.tsx
To Reproduce
- Open the StackBlitz
- Click on the button to compile the Route Handler
api/route.ts and cause the server crash
Describe the Bug
When importing bcrypt in a Route Handler and compiling that route, the process crashes, being unable to parse the HTML:
error - ./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
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>
Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
If this issue is avoided using an html-loader or similar, then further errors appear, about missing mock-aws-s3, aws-sdk, and nock modules:
error - ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:0
Module not found: Can't resolve 'mock-aws-s3'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
wait - compiling /_error (client and server)...
error - ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:0
Module not found: Can't resolve 'mock-aws-s3'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
If you install those modules, you get a bunch of critical dependency warnings and other errors like Error: /home/projects/vercel-next-js-cc6lum/.next/server/app/api/package.json does not exist
error - node_modules/@mapbox/node-pre-gyp/lib/pre-binding.js (19:10) @ exports.find
error - Error: /home/projects/vercel-next-js-cc6lum/.next/server/app/api/package.jsondoes not exist
at exports.find (webpack-internal:///(sc_server)/./node_modules/@mapbox/node-pre-gyp/lib/pre-binding.js:14:15)
at eval (webpack-internal:///(sc_server)/./node_modules/bcrypt/bcrypt.js:4:31)
at (sc_server)/./node_modules/bcrypt/bcrypt.js (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:5698:1)
at __webpack_require__ (file:///home/projects/vercel-next-js-cc6lum/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_server)/./app/api/route.ts:5:64)
at (sc_server)/./app/api/route.ts (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:873:1)
at __webpack_require__ (file:///home/projects/vercel-next-js-cc6lum/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Froute.ts&appDir=%2Fhome%2Fprojects%2Fvercel-next-js-cc6lum%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fhome%2Fprojects%2Fvercel-next-js-cc6lum&isDev=true&tsconfigPath=tsconfig.json&assetPrefix=!:13:111)
at (sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Froute.ts&appDir=%2Fhome%2Fprojects%2Fvercel-next-js-cc6lum%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fhome%2Fprojects%2Fvercel-next-js-cc6lum&isDev=true&tsconfigPath=tsconfig.json&assetPrefix=! (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:862:1)
at __webpack_require__ (file:///home/projects/vercel-next-js-cc6lum/.next/server/webpack-runtime.js:33:43)
at __webpack_exec__ (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:17114:39)
at eval (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:17115:28)
at Object.eval (file:///home/projects/vercel-next-js-cc6lum/.next/server/app/api/route.js:17118:3)
at Object.function (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:15:143671)
at Module._compile (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:219079)
at Module._extensions..js (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:219743)
at Module.load (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:217769)
at Module._load (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:215340)
at Module.require (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:218087)
at i (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:6:415284)
at _0x532db6 (https://vercelnextjscc6lum-fscu.w-credentialless.staticblitz.com/blitz.fc57b779eff411414c7b91114df9b720faaf721b.js:15:142939)
at Object.requirePage (file:///home/projects/vercel-next-js-cc6lum/node_modules/next/dist/server/require.js:88:12)
at eval (file:///home/projects/vercel-next-js-cc6lum/node_modules/next/dist/server/load-components.js:49:73)
at async Object.loadComponentsImpl [as loadComponents] (file:///home/projects/vercel-next-js-cc6lum/node_modules/next/dist/server/load-components.js:49:26)
at async DevServer.findPageComponentsImpl (file:///home/projects/vercel-next-js-cc6lum/node_modules/next/dist/server/next-server.js:599:36) {
page: '/api'
}
null
warn - ./node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
Critical dependency: the request of a dependency is an expression
Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
./node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
Critical dependency: the request of a dependency is an expression
Import trace for requested module:
./node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
./node_modules/@mapbox/node-pre-gyp/lib/pre-binding.js
./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
./node_modules/bcrypt/bcrypt.js
Critical dependency: the request of a dependency is an expression
Import trace for requested module:
./node_modules/bcrypt/bcrypt.js
./app/api/route.ts
Expected Behavior
Using bcrypt within an API Route Handler should work.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-tteixg?file=app%2Fpage.tsx
To Reproduce
api/route.tsand cause the server crashDescribe the Bug
When importing
bcryptin a Route Handler and compiling that route, the process crashes, being unable to parse the HTML:If this issue is avoided using an
html-loaderor similar, then further errors appear, about missingmock-aws-s3,aws-sdk, andnockmodules:If you install those modules, you get a bunch of critical dependency warnings and other errors like
Error: /home/projects/vercel-next-js-cc6lum/.next/server/app/api/package.json does not existExpected Behavior
Using
bcryptwithin an API Route Handler should work.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response