Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error: Cannot find module 'follow-redirects' #1834

Closed
2 tasks done
elliottsj opened this issue Dec 6, 2022 · 7 comments
Closed
2 tasks done

[Bug]: Error: Cannot find module 'follow-redirects' #1834

elliottsj opened this issue Dec 6, 2022 · 7 comments
Labels
status: awaiting user response type: bug code to address defects in shipped code

Comments

@elliottsj
Copy link

elliottsj commented Dec 6, 2022

Summary

This error page is rendered upon visiting our app:

image

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

Stack trace:

Runtime.ImportModuleError: Error: Cannot find module 'follow-redirects'
Require stack:
- /var/task/apps/dashboard/.netlify/functions-internal/___netlify-handler/handlerUtils.js
- /var/task/apps/dashboard/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
- /var/task/___netlify-handler.js
- /var/runtime/index.mjs
    at _loadUserApp (file:///var/runtime/index.mjs:1000:17)
    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)
    at async start (file:///var/runtime/index.mjs:1200:23)
    at async file:///var/runtime/index.mjs:1206:1

Netlify internal ID: 01GKMNY9325XC365GG3KHDAQNX.

Steps to reproduce

Use pnpm and deploy a site using the Netlify CLI. The command we are using is:

netlify deploy --build --prod --auth $NETLIFY_AUTH_TOKEN --site $DASHBOARD_NETLIFY_SITE_ID

Using netlify-cli@12.0.10 and @netlify/plugin-nextjs@4.29.3.

A link to a reproduction repository

No response

Next Runtime version

4.29.3

More information about your build

  • I am building using the CLI
  • 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"

[build.environment]
  NETLIFY_USE_PNPM = "true"
  NODE_VERSION = "16.18.0"

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

[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"
    Strict-Transport-Security = "max-age=31536000; includeSubDomains;"
    X-Content-Type-Options = "nosniff"
    Content-Security-Policy = "object-src 'none'; base-uri 'none';"

Your public/_redirects file

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

Your next.config.js file

`next.config.js`
import { getCommonEnvVars } from '@cohere-ai/utils/nextConfig.mjs';
import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants.js';

import nextTranspileModules from 'next-transpile-modules';
const withTM = nextTranspileModules([
  '@cohere-ai/ui',
  '@cohere-ai/blobheart-client',
  '@cohere-ai/finetune-client',
  '@cohere-ai/utils',
  '@cohere-ai/platform-components',
]);

const getNextConfig = (phase) => {
  if (phase === PHASE_PRODUCTION_BUILD || phase === PHASE_PRODUCTION_SERVER) {
    console.info('Next.js environment variables:', getCommonEnvVars(process.env));
  }

  return withTM({
    reactStrictMode: true,
    async redirects() {
      return [
        {
          source: '/confirm-email',
          destination: '/welcome/confirm-email',
          permanent: true,
        },
        {
          source: '/login',
          destination: '/welcome/login',
          permanent: true,
        },
        {
          source: '/register',
          destination: '/welcome/register',
          permanent: true,
        },
        {
          source: '/terms-of-use',
          destination: 'https://cohere.ai/terms-of-use',
          permanent: true,
        },
        {
          source: '/privacy',
          destination: 'https://cohere.ai/privacy',
          permanent: true,
        },
        {
          source: '/finetune/:path*',
          destination: '/models/custom/:path*',
          permanent: true,
        },
      ];
    },
  });
};

export default getNextConfig;

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
Dec 6, 04:58:57 PM: 2022-12-06T21:58:57.636Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'follow-redirects'\nRequire stack:\n- /var/task/apps/dashboard/.netlify/functions-internal/___netlify-handler/handlerUtils.js\n- /var/task/apps/dashboard/.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/apps/dashboard/.netlify/functions-internal/___netlify-handler/handlerUtils.js","- /var/task/apps/dashboard/.netlify/functions-internal/___netlify-handler/___netlify-handler.js","- /var/task/___netlify-handler.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1000:17)","    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)","    at async start (file:///var/runtime/index.mjs:1200:23)","    at async file:///var/runtime/index.mjs:1206:1"]}Dec 6, 04:58:57 PM: Unknown application error occurred
Runtime.ImportModuleError

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@elliottsj elliottsj added the type: bug code to address defects in shipped code label Dec 6, 2022
@elliottsj
Copy link
Author

elliottsj commented Dec 6, 2022

I believe this is introduced by #1719. Perhaps the follow-redirects npm package is not installed as expected in an accessible node_modules folder when using pnpm and the netlify CLI.

@ericapisani
Copy link

Hi @elliottsj ,

Thanks for logging a ticket and the detailed summary. Are you able to provide a minimal repro project that exhibits the issue? I've unfortunately not been able to reproduce this with one of our demo sites and installing the node modules using pnpm rather than npm

@ascorbic
Copy link
Contributor

ascorbic commented Dec 8, 2022

If using pnpm, have you enabled hoisting? See this: https://github.com/netlify/next-runtime#using-with-pnpm

@sarahetter
Copy link

As we haven't heard back in 3 weeks, I'm closing this issue. If you're still having problems, please don't hesitate to re-open.

@nickytonline
Copy link

nickytonline commented Feb 17, 2023

I'm currently getting this issue testing out a bug in Next 13 with an ISR page in the app dir. I'm using npm, but I also tried pnpm with hoisting as mentioned, but the issue persists. Not sure what the solution is yet, but I'm going to reopen this as it's blocking me test another issue.

◈ Loaded edge function ipx
◈ Loaded edge function rsc-data
◈ Rewrote URL to /.netlify/builders/___netlify-odb-handler
Request from ::1: GET /.netlify/builders/___netlify-odb-handler
{"level":"error","message":"End - Error:"}
{"errorMessage":"Cannot find module 'follow-redirects'\nRequire stack:\n- /Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js\n- /Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js\n- /Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/___netlify-odb-handler.js\n- /Users/nicktaylor/.n/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js","errorType":"Error","level":"error","stackTrace":["uire stack:","Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js","Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js","Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/___netlify-odb-handler.js","Users/nicktaylor/.n/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js","Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)","Module._load (node:internal/modules/cjs/loader:885:27)","Module.require (node:internal/modules/cjs/loader:1105:19)","require (node:internal/modules/cjs/helpers:103:18)","Object.<anonymous> (/Users/nicktaylor/dev/issues/isr-octet-stream-download/.netlify/functions-serve/.unzipped/___netlify-odb-handler/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js:12:28)","Module._compile (node:internal/modules/cjs/loader:1218:14)","Module._extensions..js (node:internal/modules/cjs/loader:1272:10)","Module.load (node:internal/modules/cjs/loader:1081:32)","Module._load (node:internal/modules/cjs/loader:922:12)","Module.require (node:internal/modules/cjs/loader:1105:19)"]}
/Users/nicktaylor/.n/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:1
...

I'm not really sure why it's not int the bundle. It's choking on this line of code.

import { http, https } from 'follow-redirects'

@nickytonline nickytonline reopened this Feb 17, 2023
@nickytonline
Copy link

I had forgot to save the .npmrc file which is why it wasn't working with pnpm or npm. After that it was all good. So just confirming that enabling hoisting via a .npmrc file works

.nprmc

public-hoist-pattern[]=*

@elliottsj
Copy link
Author

Thanks for looking into this, I can confirm that setting

public-hoist-pattern[] = follow-redirects

in .npmrc works as a workaround.

Although, in my opinion, requiring public-hoist-pattern is an anti-practice, because it defeats the benefits of pnpm's strict module layout.

In particular, if my application happens to depend on a different version of the follow-redirects package than @netlify/plugin-nextjs, let's say a hypothetical v2.0.0, then the Netlify runtime will import that instead of the expected v1.15.2.

To correctly support pnpm, public-hoist-pattern should not be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting user response type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

5 participants