发布到 heroku 时找不到模块错误
Can't find module error when publish to heroku
当我尝试在 Heroku 上发布我的 NUXT 应用程序时,我遇到了这个错误
服务器错误
应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以了解详细信息。
应用程序运行本地正常一切正常。
这是构建日志
Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_PRODUCTION=false
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 14.x...
remote: Downloading and installing node 14.16.0...
remote: Using default npm version: 6.14.11
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: > ejs@2.7.4 postinstall /tmp/build_216782e5/node_modules/ejs
remote: > node ./postinstall.js
remote:
remote:
remote: > fsevents@1.2.13 install /tmp/build_216782e5/node_modules/watchpack-chokidar2/node_modules/fsevents
remote: > node install.js
remote:
remote:
remote: Skipping 'fsevents' build as platform linux is not supported
remote:
remote: > core-js@2.6.12 postinstall /tmp/build_216782e5/node_modules/@nuxt/babel-preset-app/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > nuxt@2.14.12 postinstall /tmp/build_216782e5/node_modules/nuxt
remote: > opencollective || exit 0
remote:
remote:
remote: > core-js@2.6.12 postinstall /tmp/build_216782e5/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js@3.8.3 postinstall /tmp/build_216782e5/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > bcrypt@5.0.1 install /tmp/build_216782e5/node_modules/bcrypt
remote: > node-pre-gyp install --fallback-to-build
remote:
remote: [bcrypt] Success: "/tmp/build_216782e5/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
remote:
remote: > deasync@0.1.21 install /tmp/build_216782e5/node_modules/deasync
remote: > node ./build.js
remote:
remote: `linux-x64-node-14` exists; testing
remote: Binary is fine; exiting
remote: added 2157 packages in 31.908s
remote:
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > temps4care@1.0.0 heroku-postbuild /tmp/build_216782e5
remote: > npm run build
remote:
remote:
remote: > temps4care@1.0.0 build /tmp/build_216782e5
remote: > nuxt build
remote:
remote: ℹ Using Tailwind CSS from ~/assets/css/tailwind.css
remote: ℹ Merging Tailwind config from ~/tailwind.config.js
remote:
remote: ERROR ServerMiddleware Error: Cannot find module '../middlewares/is-admin'
remote: Require stack:
remote: - /tmp/build_216782e5/api/routes/applications.js
remote: - /tmp/build_216782e5/api/index.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/core/dist/core.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/cli/dist/cli-index.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/cli/dist/cli.js
remote: - /tmp/build_216782e5/node_modules/nuxt/bin/nuxt.js
remote:
remote: Error: Cannot find module '../middlewares/is-admin'
remote: Require stack:
remote: - api/routes/applications.js
remote: - api/index.js
remote: - node_modules/@nuxt/core/dist/core.js
remote: - node_modules/@nuxt/cli/dist/cli-index.js
remote: - node_modules/@nuxt/cli/dist/cli.js
remote: - node_modules/nuxt/bin/nuxt.js
remote: at Object.<anonymous> (api/routes/applications.js:5:17)
remote: at Generator.next (<anonymous>)
remote: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
remote:
remote: ℹ Production build
remote: ℹ Bundling only for client side
remote: ℹ Target: static
remote: ✔ Builder initialized
remote: ✔ Nuxt files generated
remote: ℹ Compiling Client
remote: ✔ Client: Compiled successfully in 46.62s
remote:
remote: Built at: 03/20/2021 8:43:32 AM
remote: Entrypoint app = 04a9315.js 3dd8788.js 959bf8b.js 6f6dc41.js
remote: ℹ Generating output directory: dist/
remote: ℹ Generating pages
remote: ✔ Generated route "/signappsucc"
remote: ✔ Generated route "/"
remote: ✔ Generated route "/admin/dashboard"
remote: ✔ Generated route "/auth/forgetpassword/message"
remote: ✔ Generated route "/auth/forgetpassword"
remote: ✔ Generated route "/auth/login"
remote: ✔ Generated route "/auth/signup"
remote: ✔ Client-side fallback created: 200.html
remote:
remote: -----> Caching build
remote: - node_modules
remote:
remote: -----> Pruning devDependencies
remote: Skipping because NPM_CONFIG_PRODUCTION is 'false'
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> web
remote:
remote: -----> Compressing...
remote: Done: 92.6M
remote: -----> Launching...
remote: Released v6
remote: https://temps4care.herokuapp.com/ deployed to Heroku
这是 heroku 应用程序的日志
2021-03-20T09:08:20.116879+00:00 app[web.1]: - api/index.js
2021-03-20T09:08:20.116879+00:00 app[web.1]: - node_modules/@nuxt/core/dist/core.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/@nuxt/cli/dist/cli-index.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/@nuxt/cli/dist/cli.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/nuxt/bin/nuxt.js
2021-03-20T09:08:20.116881+00:00 app[web.1]: at Object.<anonymous> (api/routes/applications.js:5:17)
2021-03-20T09:08:20.116881+00:00 app[web.1]: at Generator.next (<anonymous>)
2021-03-20T09:08:20.116882+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-03-20T09:08:20.116882+00:00 app[web.1]:
2021-03-20T09:08:20.122522+00:00 heroku[router]: at=info method=GET path="/robots.txt" host=application.temps4care.co.uk request_id=ec0a765b-e6be-4df1-9b72-c52e99f51c89 fwd="41.237.133.17" dyno=web.1 connect=2ms service=14ms status=500 bytes=1199 protocol=https
哦我终于解决了
构建日志中的错误很清楚
ServerMiddleware 错误:找不到模块'../middlewares/is-admin'
我认为 Heroku 是区分大小写的 我导入了模块 ../middlewares/is-admin 但是文件名是 is-Admin 所以 Heroku 抱怨了这一点。
当我将文件名更改为 is-admin 时一切正常
当我尝试在 Heroku 上发布我的 NUXT 应用程序时,我遇到了这个错误
服务器错误 应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以了解详细信息。
应用程序运行本地正常一切正常。
这是构建日志
Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_PRODUCTION=false
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 14.x...
remote: Downloading and installing node 14.16.0...
remote: Using default npm version: 6.14.11
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: > ejs@2.7.4 postinstall /tmp/build_216782e5/node_modules/ejs
remote: > node ./postinstall.js
remote:
remote:
remote: > fsevents@1.2.13 install /tmp/build_216782e5/node_modules/watchpack-chokidar2/node_modules/fsevents
remote: > node install.js
remote:
remote:
remote: Skipping 'fsevents' build as platform linux is not supported
remote:
remote: > core-js@2.6.12 postinstall /tmp/build_216782e5/node_modules/@nuxt/babel-preset-app/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > nuxt@2.14.12 postinstall /tmp/build_216782e5/node_modules/nuxt
remote: > opencollective || exit 0
remote:
remote:
remote: > core-js@2.6.12 postinstall /tmp/build_216782e5/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js@3.8.3 postinstall /tmp/build_216782e5/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > bcrypt@5.0.1 install /tmp/build_216782e5/node_modules/bcrypt
remote: > node-pre-gyp install --fallback-to-build
remote:
remote: [bcrypt] Success: "/tmp/build_216782e5/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
remote:
remote: > deasync@0.1.21 install /tmp/build_216782e5/node_modules/deasync
remote: > node ./build.js
remote:
remote: `linux-x64-node-14` exists; testing
remote: Binary is fine; exiting
remote: added 2157 packages in 31.908s
remote:
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > temps4care@1.0.0 heroku-postbuild /tmp/build_216782e5
remote: > npm run build
remote:
remote:
remote: > temps4care@1.0.0 build /tmp/build_216782e5
remote: > nuxt build
remote:
remote: ℹ Using Tailwind CSS from ~/assets/css/tailwind.css
remote: ℹ Merging Tailwind config from ~/tailwind.config.js
remote:
remote: ERROR ServerMiddleware Error: Cannot find module '../middlewares/is-admin'
remote: Require stack:
remote: - /tmp/build_216782e5/api/routes/applications.js
remote: - /tmp/build_216782e5/api/index.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/core/dist/core.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/cli/dist/cli-index.js
remote: - /tmp/build_216782e5/node_modules/@nuxt/cli/dist/cli.js
remote: - /tmp/build_216782e5/node_modules/nuxt/bin/nuxt.js
remote:
remote: Error: Cannot find module '../middlewares/is-admin'
remote: Require stack:
remote: - api/routes/applications.js
remote: - api/index.js
remote: - node_modules/@nuxt/core/dist/core.js
remote: - node_modules/@nuxt/cli/dist/cli-index.js
remote: - node_modules/@nuxt/cli/dist/cli.js
remote: - node_modules/nuxt/bin/nuxt.js
remote: at Object.<anonymous> (api/routes/applications.js:5:17)
remote: at Generator.next (<anonymous>)
remote: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
remote:
remote: ℹ Production build
remote: ℹ Bundling only for client side
remote: ℹ Target: static
remote: ✔ Builder initialized
remote: ✔ Nuxt files generated
remote: ℹ Compiling Client
remote: ✔ Client: Compiled successfully in 46.62s
remote:
remote: Built at: 03/20/2021 8:43:32 AM
remote: Entrypoint app = 04a9315.js 3dd8788.js 959bf8b.js 6f6dc41.js
remote: ℹ Generating output directory: dist/
remote: ℹ Generating pages
remote: ✔ Generated route "/signappsucc"
remote: ✔ Generated route "/"
remote: ✔ Generated route "/admin/dashboard"
remote: ✔ Generated route "/auth/forgetpassword/message"
remote: ✔ Generated route "/auth/forgetpassword"
remote: ✔ Generated route "/auth/login"
remote: ✔ Generated route "/auth/signup"
remote: ✔ Client-side fallback created: 200.html
remote:
remote: -----> Caching build
remote: - node_modules
remote:
remote: -----> Pruning devDependencies
remote: Skipping because NPM_CONFIG_PRODUCTION is 'false'
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> web
remote:
remote: -----> Compressing...
remote: Done: 92.6M
remote: -----> Launching...
remote: Released v6
remote: https://temps4care.herokuapp.com/ deployed to Heroku
这是 heroku 应用程序的日志
2021-03-20T09:08:20.116879+00:00 app[web.1]: - api/index.js
2021-03-20T09:08:20.116879+00:00 app[web.1]: - node_modules/@nuxt/core/dist/core.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/@nuxt/cli/dist/cli-index.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/@nuxt/cli/dist/cli.js
2021-03-20T09:08:20.116880+00:00 app[web.1]: - node_modules/nuxt/bin/nuxt.js
2021-03-20T09:08:20.116881+00:00 app[web.1]: at Object.<anonymous> (api/routes/applications.js:5:17)
2021-03-20T09:08:20.116881+00:00 app[web.1]: at Generator.next (<anonymous>)
2021-03-20T09:08:20.116882+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-03-20T09:08:20.116882+00:00 app[web.1]:
2021-03-20T09:08:20.122522+00:00 heroku[router]: at=info method=GET path="/robots.txt" host=application.temps4care.co.uk request_id=ec0a765b-e6be-4df1-9b72-c52e99f51c89 fwd="41.237.133.17" dyno=web.1 connect=2ms service=14ms status=500 bytes=1199 protocol=https
哦我终于解决了
构建日志中的错误很清楚
ServerMiddleware 错误:找不到模块'../middlewares/is-admin'
我认为 Heroku 是区分大小写的 我导入了模块 ../middlewares/is-admin 但是文件名是 is-Admin 所以 Heroku 抱怨了这一点。 当我将文件名更改为 is-admin 时一切正常