vue.jsherokunuxt.jsheroku-cliheroku-toolbelt

Can't find module error when publish to heroku


When i try to publish my NUXT Application on Heroku I Got This Error

Server error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.

The Application Running Locally Fine Everything work.

this is building logs

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

this is the logs of the heroku application

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

Solution

  • oh finally I solved it

    the error in the building logs is clear

    ServerMiddleware Error: Cannot find module '../middlewares/is-admin'

    I think Heroku is case sensitive I import the module ../middlewares/is-admin but the file name was is-Admin so Heroku complained about that. when I changed the file name to is-admin everything works fine