next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: `Runtime.ImportModuleError - Error: Cannot find module 'follow-redirects'` when deploying with netlify-cli and pnpm

Open elliottsj opened this issue 8 months ago • 5 comments

Summary

When using:

A module import error Cannot find module 'follow-redirects' occurs when visiting the site.

A link to a reproduction repository

https://github.com/elliottsj/nextjs-netlify-follow-redirects-issue

https://nextjs-follow-redirects-docs.netlify.app/

Expected Result

No error

Actual Result

Runtime.ImportModuleError - Error: Cannot find module 'follow-redirects' Require stack: - /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js - /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js - /var/task/___netlify-handler.js - /var/runtime/index.mjs

Steps to reproduce

Visit https://github.com/elliottsj/nextjs-netlify-follow-redirects-issue and follow the steps in the README.

To deploy to a new Netlify site, change the --site value in apps/docs/package.json.

Next Runtime version

4.40.2

Is your issue related to the app directory?

  • [ ] Yes, I am using the app directory

More information about your build

  • [X] I am building using the CLI
  • [x] I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml`
[build]
  command = "pnpm run build"
  base = "apps/docs"
  publish = ".next"

[build.environment]
  NETLIFY_USE_PNPM = "true"

[[plugins]]
package = "@netlify/plugin-nextjs"

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
module.exports = {
  reactStrictMode: true,
  transpilePackages: ["ui"],
};

Builds logs (or link to your logs)

Build logs
❯ pnpm run deploy --filter=docs --force

> my-turborepo@ deploy /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue
> turbo run deploy --concurrency=1 "--filter=docs" "--force"

╭────────────────────────────────────────────────────────────────────────╮
│                                                                        │
│                  Update available v1.10.14 ≫ v1.10.15                  │
│    Changelog: https://github.com/vercel/turbo/releases/tag/v1.10.15    │
│               Run "npx @turbo/codemod update" to update                │
│                                                                        │
│      Follow @turborepo for updates: https://twitter.com/turborepo      │
╰────────────────────────────────────────────────────────────────────────╯
• Packages in scope: docs
• Running deploy in 1 packages
• Remote caching disabled
docs:deploy: cache bypass, force executing ac934134be8bf4d8
docs:deploy:
docs:deploy: > [email protected] deploy /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs
docs:deploy: > netlify deploy --build --prod --auth $NETLIFY_AUTH_TOKEN --site 412ef113-aa7d-4f00-9c58-8cc9a4a885e1 --skip-functions-cache
docs:deploy:
docs:deploy:
docs:deploy: Netlify Build
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: ❯ Version
docs:deploy:   @netlify/build 29.22.2
docs:deploy:
docs:deploy: ❯ Flags
docs:deploy:   {}
docs:deploy:
docs:deploy: ❯ Current directory
docs:deploy:   /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs
docs:deploy:
docs:deploy: ❯ Config file
docs:deploy:   /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs/netlify.toml
docs:deploy:
docs:deploy: ❯ Context
docs:deploy:   dev
docs:deploy:
docs:deploy: ❯ Using Next.js Runtime - v4.40.2
docs:deploy:
docs:deploy: @netlify/plugin-nextjs (onPreBuild event)
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: No Next.js cache to restore.
docs:deploy: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
docs:deploy:
docs:deploy: (@netlify/plugin-nextjs onPreBuild completed in 797ms)
docs:deploy:
docs:deploy: build.command from netlify.toml
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: $ pnpm run build
docs:deploy:
docs:deploy: > [email protected] build /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs
docs:deploy: > next build
docs:deploy:
docs:deploy:    Creating an optimized production build ...
docs:deploy:  ✓ Compiled successfully
docs:deploy:    Linting and checking validity of types ...
docs:deploy:    Collecting page data ...
docs:deploy:    Generating static pages (0/4) ...
   Generating static pages (1/4)
   Generating static pages (2/4)
   Generating static pages (3/4)
 ✓ Generating static pages (4/4)
docs:deploy:    Finalizing page optimization ...
docs:deploy:    Collecting build traces ...
docs:deploy:
docs:deploy: Route (app)                              Size     First Load JS
docs:deploy: ┌ ○ /                                    745 B          81.1 kB
docs:deploy: └ ○ /_not-found                          883 B          81.2 kB
docs:deploy: + First Load JS shared by all            80.3 kB
docs:deploy:   ├ chunks/05ad1faf-649722ada73fd971.js  51 kB
docs:deploy:   ├ chunks/183-2889461cbead6e9f.js       27.5 kB
docs:deploy:   ├ chunks/main-app-f0d99205d70d78b5.js  232 B
docs:deploy:   └ chunks/webpack-bf1a64d1eafd2816.js   1.66 kB
docs:deploy:
docs:deploy:
docs:deploy: ○  (Static)  automatically rendered as static HTML (uses no initial props)
docs:deploy:
docs:deploy:
docs:deploy: (build.command completed in 9.1s)
docs:deploy:
docs:deploy: @netlify/plugin-nextjs (onBuild event)
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: apiLambdas []
docs:deploy: ssrLambdas []
docs:deploy: Moving static page files to serve from CDN...
docs:deploy: Moved 6 files
docs:deploy: You are not using Netlify Edge Functions for image format detection. Set env var "NEXT_FORCE_EDGE_IMAGES=true" to enable.
docs:deploy: Netlify configuration property "redirects" value changed to [
docs:deploy:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
docs:deploy:   {
docs:deploy:     from: '/_next/image*',
docs:deploy:     query: { url: ':url', w: ':width', q: ':quality' },
docs:deploy:     to: '/_ipx/w_:width,q_:quality/:url',
docs:deploy:     status: 301
docs:deploy:   },
docs:deploy:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
docs:deploy:   {
docs:deploy:     from: '/api/*',
docs:deploy:     to: '/.netlify/functions/___netlify-handler',
docs:deploy:     status: 200
docs:deploy:   },
docs:deploy:   {
docs:deploy:     from: '/*',
docs:deploy:     to: '/.netlify/functions/___netlify-handler',
docs:deploy:     status: 200,
docs:deploy:     conditions: { Cookie: [Array] },
docs:deploy:     force: true
docs:deploy:   },
docs:deploy:   {
docs:deploy:     from: '/_next/data/qjjfVGZxqabXDPFcxPBE-/_not-found.json',
docs:deploy:     to: '/.netlify/functions/___netlify-handler',
docs:deploy:     status: 200,
docs:deploy:     force: false
docs:deploy:   },
docs:deploy:   {
docs:deploy:     from: '/_not-found',
docs:deploy:     to: '/.netlify/functions/___netlify-handler',
docs:deploy:     status: 200,
docs:deploy:     force: false
docs:deploy:   },
docs:deploy:   {
docs:deploy:     from: '/*',
docs:deploy:     to: '/.netlify/functions/___netlify-handler',
docs:deploy:     status: 200
docs:deploy:   }
docs:deploy: ].
docs:deploy:
docs:deploy: (@netlify/plugin-nextjs onBuild completed in 974ms)
docs:deploy:
docs:deploy: Functions bundling
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: Packaging Functions from .netlify/functions-internal directory:
docs:deploy:  - ___netlify-handler/___netlify-handler.js
docs:deploy:  - ___netlify-odb-handler/___netlify-odb-handler.js
docs:deploy:  - _ipx/_ipx.js
docs:deploy:
docs:deploy:
docs:deploy: (Functions bundling completed in 15s)
docs:deploy:
docs:deploy: Edge Functions bundling
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: Packaging Edge Functions from .netlify/edge-functions directory:
docs:deploy:  - rsc-data
docs:deploy:
docs:deploy: (Edge Functions bundling completed in 731ms)
docs:deploy:
docs:deploy: @netlify/plugin-nextjs (onPostBuild event)
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: Next.js cache saved.
docs:deploy:
docs:deploy: (@netlify/plugin-nextjs onPostBuild completed in 52ms)
docs:deploy:
docs:deploy: Netlify Build Complete
docs:deploy: ────────────────────────────────────────────────────────────────
docs:deploy:
docs:deploy: (Netlify Build completed in 27.6s)
docs:deploy: Deploy path:        /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs/.next
docs:deploy: Configuration path: /Users/spencer/Dev/elliottsj/nextjs-netlify-follow-redirects-issue/apps/docs/netlify.toml
docs:deploy: Deploying to main site URL...
docs:deploy: - Hashing files...
docs:deploy: - Looking for a functions cache...
docs:deploy: ✔ Ignoring functions cache (use without --skip-functions-cache to change)
docs:deploy: ✔ Finished hashing 24 files, 3 functions and edge functions
docs:deploy: - CDN diffing files...
docs:deploy: ✔ CDN requesting 9 files and 2 functions
docs:deploy: - Uploading 12 files
docs:deploy: ✔ Finished uploading 12 assets
docs:deploy: - Waiting for deploy to go live...
docs:deploy: ✔ Deploy is live!
docs:deploy:
docs:deploy: Build logs:        https://app.netlify.com/sites/nextjs-follow-redirects-docs/deploys/65259c8e687e5f1af68d21b6
docs:deploy: Function logs:     https://app.netlify.com/sites/nextjs-follow-redirects-docs/functions
docs:deploy: Unique deploy URL: https://65259c8e687e5f1af68d21b6--nextjs-follow-redirects-docs.netlify.app
docs:deploy: Website URL:       https://nextjs-follow-redirects-docs.netlify.app

 Tasks:    1 successful, 1 total
Cached:    0 cached, 1 total
  Time:    42.655s

Function logs

Function logs
Oct 10, 03:10:50 PM: 976f7d04 2023-10-10T19:10:50.697Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'follow-redirects'\nRequire stack:\n- /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js\n- /var/task/___netlify-handler.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'follow-redirects'","Require stack:","- /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js","- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js","- /var/task/___netlify-handler.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1061:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)","    at async start (file:///var/runtime/index.mjs:1256:23)","    at async file:///var/runtime/index.mjs:1262:1"]}Oct 10, 03:10:50 PM: 976f7d04 2023-10-10T19:10:50.903Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'follow-redirects'\nRequire stack:\n- /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js\n- /var/task/___netlify-handler.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'follow-redirects'","Require stack:","- /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js","- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js","- /var/task/___netlify-handler.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1061:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)","    at async start (file:///var/runtime/index.mjs:1256:23)","    at async file:///var/runtime/index.mjs:1262:1"]}Oct 10, 03:10:50 PM: 976f7d04 Unknown application error occurredOct 10, 03:10:50 PM: 976f7d04 Runtime.ImportModuleErrorOct 10, 03:10:50 PM: 976f7d04 Duration: 224.65 ms	Memory Usage: 18 MB	

.next JSON files

generated .next JSON files

.next/build-manifest.json

{
  "polyfillFiles": [
    "static/chunks/polyfills.js"
  ],
  "devFiles": [
    "static/chunks/react-refresh.js"
  ],
  "ampDevFiles": [],
  "lowPriorityFiles": [
    "static/development/_buildManifest.js",
    "static/development/_ssgManifest.js"
  ],
  "rootMainFiles": [],
  "pages": {
    "/": [
      "static/chunks/webpack.js",
      "static/chunks/main.js",
      "static/chunks/pages/index.js"
    ],
    "/_app": [
      "static/chunks/webpack.js",
      "static/chunks/main.js",
      "static/chunks/pages/_app.js"
    ],
    "/_error": [
      "static/chunks/webpack.js",
      "static/chunks/main.js",
      "static/chunks/pages/_error.js"
    ]
  },
  "ampFirstPages": []
}

.next/server/pages-manifest.json

{
  "/_app": "pages/_app.js",
  "/_error": "pages/_error.js",
  "/_document": "pages/_document.js",
  "/": "pages/index.js"
}

elliottsj avatar Oct 10 '23 19:10 elliottsj