Remix App deploy: Runtime.HandlerNotFound - server.handler is undefined or not exported

Hey there,
I’m currently trying to deploy my remix.run app to Netlify.
As package manager I first used pnpm but that didn’t seem to work as expected. See Stack Overflow question. Thus I switched back to npm for now and tried again. The first issue (complaining about missing deps) didn’t occur anymore. However now I get another error:

Runtime.HandlerNotFound - server.handler is undefined or not exported

I decided to create a project from scratch based on this Netlify Blog (for testing), but both errors occur there too:

  1. When using pnpm it complains about missing deps (See)
  2. Using npm: After executing npm run build + netlify deploy this error occurs in the browser: Runtime.HandlerNotFound - server.handler is undefined or not exported

Dummy Repo: GitHub - bennodev19/rad-remix-app: Netlify Issue
Dummy Site-ID: 12cdfb8e-8eb4-4164-a39c-7a607d93acb2
Dummy Site-Name: rad-remix-app-9000
Internal Error-ID: 01GG1NF7190K9QZ16VPP05JW8Z

cheers

Are you able to make the dummy repository public @BennoDev ?

ohh right… sry didn’t realize that it wasn’t public… now its public.
thanks ^^

I deployed the test repository to https://peppy-quokka-4e94a6.netlify.app/ and it works as I suspect it should.

Thanks for the quick reply ^^
I deployed it to https://6354cbd06b1a7630f6311831--rad-remix-app-9000.netlify.app/
and somehow it doesn’t work. I’ll try it again and see whether I can find my issue.
thanks ^^

Did it also work with pnpm in your case?

I didn’t change anything, so it used the pnpm run build command in the netlify.toml.

However, as there is no pnpm-lock.yaml in the repository (see: Out of the box support for pnpm!), npm was used to install dependencies.

But the build script then runs npm run build:css && remix build so i’m really not sure why you’re using pnpm in the first place.

yeah… that was from testing and switching back to npm (which seems like I didn’t do properly as I missed updating it in netlify.toml ^^). I built and deployed this test app locally, thus the pnpm-lock.yaml was previously always present.

I tried to deploy the app again (with exactly this codebase using npm (Release Tag: npm-test-1)) executing this commands:

# Checkout project
..

# Install deps & build 
> npm install
> npm run build

# Init Netlify
> netlify init
- "Create & configure a new site"
- "x-team"
- "rad-remix-app2"

# Deploy built app
> netlify deploy

However, I still get that same error when visiting the generated Website Draft URL:
https://635534dd2ef0e172e22f64a5--rad-remix-app2.netlify.app/

Oct 23, 03:42:46 PM: 22483dc2 Unknown application error occurredOct 23, 03:42:46 PM: 22483dc2 Runtime.HandlerNotFoundOct 23, 03:42:46 PM: 22483dc2 2022-10-23T13:42:46.742Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.HandlerNotFound","errorMessage":"server.handler is undefined or not exported","stack":["Runtime.HandlerNotFound: server.handler is undefined or not exported","    at Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:979:15)","    at async start (file:///var/runtime/index.mjs:1137:23)","    at async file:///var/runtime/index.mjs:1143:1"]}Oct 23, 03:42:46 PM: 22483dc2 2022-10-23T13:42:47.111Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.HandlerNotFound","errorMessage":"server.handler is undefined or not exported","stack":["Runtime.HandlerNotFound: server.handler is undefined or not exported","    at Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:979:15)","    at async start (file:///var/runtime/index.mjs:1137:23)","    at async file:///var/runtime/index.mjs:1143:1"]}Oct 23, 03:42:46 PM: 22483dc2 Unknown application error occurredOct 23, 03:42:46 PM: 22483dc2 Runtime.HandlerNotFound

Seems like I’m missing something.

cheers

Does it happen when you deploy via Git?

thanks for the quick reply ^^
If I tried to deploy the site via github by selecting:
Add new siteImport an existing projectGithub[select project]

I get the before mentioned dependency issue which I guess is related to pnpm.
I’ll roll back to npm and try again via github…

4:10:10 PM: Build ready to start
4:10:12 PM: build-image version: 8b79b5e0c585f1b3f892b8032389b4b4b188d887 (focal)
4:10:12 PM: build-image tag: v4.14.0
4:10:12 PM: buildbot version: 1e88a9b854b49555d21dc539e2b8bf5fb78a8f57
4:10:12 PM: Fetching cached dependencies
4:10:12 PM: Failed to fetch cache, continuing with build
4:10:12 PM: Starting to prepare the repo for build
4:10:12 PM: No cached dependencies found. Cloning fresh repo
4:10:12 PM: git clone https://github.com/bennodev19/rad-remix-app
4:10:12 PM: Preparing Git Reference refs/heads/master
4:10:13 PM: Parsing package.json dependencies
4:10:14 PM: Starting build script
4:10:14 PM: Installing dependencies
4:10:14 PM: Python version set to 2.7
4:10:14 PM: v16.18.0 is already installed.
4:10:14 PM: Now using node v16.18.0 (npm v8.19.2)
4:10:14 PM: Enabling node corepack
4:10:15 PM: Started restoring cached build plugins
4:10:15 PM: Finished restoring cached build plugins
4:10:15 PM: Attempting ruby version 2.7.2, read from environment
4:10:15 PM: Using ruby version 2.7.2
4:10:15 PM: Using PHP version 8.0
4:10:16 PM: No pnpm workspaces detected
4:10:16 PM: Started restoring cached node modules
4:10:16 PM: Finished restoring cached node modules
4:10:16 PM: Installing NPM modules using PNPM version 7.13.4
4:10:16 PM: Lockfile is up to date, resolution step is skipped
4:10:16 PM: Progress: resolved 1, reused 0, downloaded 0, added 0
4:10:17 PM: Packages: +977
4:10:17 PM: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4:10:17 PM: Packages are hard linked from the content-addressable store to the virtual store.
4:10:17 PM:   Content-addressable store is at: /opt/build/.pnpm-store/v3
4:10:17 PM:   Virtual store is at:             node_modules/.pnpm
4:10:17 PM: Progress: resolved 977, reused 0, downloaded 57, added 57
4:10:18 PM: Progress: resolved 977, reused 0, downloaded 175, added 174
4:10:19 PM: Progress: resolved 977, reused 0, downloaded 400, added 395
4:10:20 PM: Progress: resolved 977, reused 0, downloaded 548, added 540
4:10:21 PM: Progress: resolved 977, reused 0, downloaded 719, added 715
4:10:22 PM: Progress: resolved 977, reused 0, downloaded 827, added 826
4:10:23 PM: Progress: resolved 977, reused 0, downloaded 861, added 859
4:10:24 PM: Progress: resolved 977, reused 0, downloaded 940, added 935
4:10:26 PM: Progress: resolved 977, reused 0, downloaded 976, added 975
4:10:26 PM: .../deasync@0.1.28/node_modules/deasync install$ node ./build.js
4:10:26 PM: .../node_modules/core-js-pure postinstall$ node -e "try{require('./postinstall')}catch(e){}"
4:10:26 PM: .../deasync@0.1.28/node_modules/deasync install: `linux-x64-node-16` exists; testing
4:10:27 PM: Progress: resolved 977, reused 0, downloaded 977, added 977, done
4:10:27 PM: .../node_modules/core-js-pure postinstall: Done
4:10:27 PM: .../deasync@0.1.28/node_modules/deasync install: Binary is fine; exiting
4:10:27 PM: .../deasync@0.1.28/node_modules/deasync install: Done
4:10:27 PM: .../esbuild@0.14.51/node_modules/esbuild postinstall$ node install.js
4:10:27 PM: .../esbuild@0.14.51/node_modules/esbuild postinstall: Done
4:10:27 PM: dependencies:
4:10:27 PM: + @netlify/functions 1.3.0
4:10:27 PM: + @remix-run/netlify 1.7.3
4:10:27 PM: + @remix-run/node 1.7.3
4:10:27 PM: + @remix-run/react 1.7.3
4:10:27 PM: + cross-env 7.0.3
4:10:27 PM: + react 18.2.0
4:10:27 PM: + react-dom 18.2.0
4:10:27 PM: devDependencies:
4:10:27 PM: + @remix-run/dev 1.7.3
4:10:27 PM: + @remix-run/eslint-config 1.7.3
4:10:27 PM: + @remix-run/serve 1.7.3
4:10:27 PM: + @types/react 18.0.21
4:10:27 PM: + @types/react-dom 18.0.6
4:10:27 PM: + autoprefixer 10.4.12
4:10:27 PM: + concurrently 7.5.0
4:10:27 PM: + eslint 8.26.0
4:10:27 PM: + postcss 8.4.18
4:10:27 PM: + tailwindcss 3.2.1
4:10:27 PM: + typescript 4.8.4
4:10:27 PM: Done in 10.8s
4:10:27 PM: NPM modules installed using PNPM
4:10:27 PM: Started restoring cached go cache
4:10:27 PM: Finished restoring cached go cache
4:10:27 PM: Installing Go version 1.17 (requested 1.17)
4:10:31 PM: unset GOOS;
4:10:31 PM: unset GOARCH;
4:10:31 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
4:10:31 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
4:10:31 PM: go version >&2;
4:10:31 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
4:10:31 PM: go version go1.17 linux/amd64
4:10:31 PM: Installing missing commands
4:10:31 PM: Verify run directory
4:10:33 PM: ​
4:10:33 PM: ────────────────────────────────────────────────────────────────
4:10:33 PM:   Netlify Build                                                 
4:10:33 PM: ────────────────────────────────────────────────────────────────
4:10:33 PM: ​
4:10:33 PM: ❯ Version
4:10:33 PM:   @netlify/build 28.1.1
4:10:33 PM: ​
4:10:33 PM: ❯ Flags
4:10:33 PM:   baseRelDir: true
4:10:33 PM:   buildId: 63554b425b4a5e7a17b2448d
4:10:33 PM:   deployId: 63554b425b4a5e7a17b2448f
4:10:33 PM: ​
4:10:33 PM: ❯ Current directory
4:10:33 PM:   /opt/build/repo
4:10:33 PM: ​
4:10:33 PM: ❯ Config file
4:10:33 PM:   /opt/build/repo/netlify.toml
4:10:33 PM: ​
4:10:33 PM: ❯ Context
4:10:33 PM:   production
4:10:33 PM: ​
4:10:33 PM: ────────────────────────────────────────────────────────────────
4:10:33 PM:   1. build.command from netlify.toml                            
4:10:33 PM: ────────────────────────────────────────────────────────────────
4:10:33 PM: ​
4:10:33 PM: $ pnpm run build
4:10:33 PM: > @ build /opt/build/repo
4:10:33 PM: > pnpm run build:css && remix build
4:10:33 PM: > @ build:css /opt/build/repo
4:10:33 PM: > tailwindcss -m -i ./styles/app.css -o app/styles/app.css
4:10:34 PM: Rebuilding...
4:10:34 PM: Done in 193ms.
4:10:35 PM: Building Remix app in production mode...
4:10:35 PM: Built in 290ms
4:10:35 PM: ​
4:10:35 PM: (build.command completed in 2.2s)
4:10:35 PM: ​
4:10:35 PM: ────────────────────────────────────────────────────────────────
4:10:35 PM:   2. Functions bundling                                         
4:10:35 PM: ────────────────────────────────────────────────────────────────
4:10:35 PM: ​
4:10:35 PM: Packaging Functions from .netlify/functions-internal directory:
4:10:35 PM:  - server.js
4:10:35 PM: ​
4:10:35 PM: ​
4:10:35 PM: ────────────────────────────────────────────────────────────────
4:10:35 PM:   Dependencies installation error                               
4:10:35 PM: ────────────────────────────────────────────────────────────────
4:10:35 PM: ​
4:10:35 PM:   Error message
4:10:35 PM:   A Netlify Function failed to require one of its dependencies.
4:10:35 PM:   Please make sure it is present in the site's top-level "package.json".
​
4:10:35 PM:   In file "/opt/build/repo/.netlify/functions-internal/server.js"
4:10:35 PM:   Cannot find module 'loose-envify'
4:10:35 PM:   Require stack:
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/resolve.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/traverse.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/src_files.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/index.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/index.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/index.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/index.js
4:10:35 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/main.js
4:10:35 PM: ​
4:10:35 PM:   Resolved config
4:10:35 PM:   build:
4:10:35 PM:     command: pnpm run build
4:10:35 PM:     commandOrigin: config
4:10:35 PM:     publish: /opt/build/repo/public
4:10:35 PM:     publishOrigin: config
4:10:35 PM:   headers:
4:10:35 PM:     - for: /build/*
      values:
        Cache-Control: public, max-age=31536000, s-maxage=31536000
  headersOrigin: config
  redirects:
    - from: /*
      status: 200
      to: /.netlify/functions/server
  redirectsOrigin: config
Caching artifacts
4:10:35 PM: Started saving node modules
4:10:36 PM: Finished saving node modules
4:10:36 PM: Started saving build plugins
4:10:36 PM: Finished saving build plugins
4:10:36 PM: Started saving pip cache
4:10:36 PM: Finished saving pip cache
4:10:36 PM: Started saving emacs cask dependencies
4:10:36 PM: Finished saving emacs cask dependencies
4:10:36 PM: Started saving maven dependencies
4:10:36 PM: Finished saving maven dependencies
4:10:36 PM: Started saving boot dependencies
4:10:36 PM: Finished saving boot dependencies
4:10:36 PM: Started saving rust rustup cache
4:10:36 PM: Finished saving rust rustup cache
4:10:36 PM: Started saving go dependencies
4:10:36 PM: Finished saving go dependencies
4:10:36 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:10:36 PM: Creating deploy upload records
4:10:36 PM: Failing build: Failed to build site
4:10:36 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:10:36 PM: Finished processing build request in 24.770355526s

Note: The repo status deposited at the tag pnpm-deploy-via-github was used.

cheers

Using npm it seems like to work ;D
but does sb know why I got the other issue regarding pnpm (See Stack Overflow) as I would love to continue using pnpm
thanks ^^

Note: The repo status deposited at the tag npm-deploy-via-github-2 was used.

→ The issue regarding Runtime.HandlerNotFound was partly resolved by simply avoiding manual deploy and only deploying via github.

Thanks for the help so far ^^

cheers

Maybe this will help:

:pray: thanks that resolved the pnpm issue ^^

1 Like