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

Failed to create esm bundled application #7467

Open
1 task done
KnisterPeter opened this issue Sep 18, 2023 · 9 comments · May be fixed by #7779
Open
1 task done

Failed to create esm bundled application #7467

KnisterPeter opened this issue Sep 18, 2023 · 9 comments · May be fixed by #7779

Comments

@KnisterPeter
Copy link

What version of Remix are you using?

2.0.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

  • Create a new app with pnpx create-remix@latest test.
  • In remix.config.js add serverDependenciesToBundle: [/.*/]
  • Run pnpm run dev.

Expected Behavior

The application should start.

Actual Behavior

The application actually fails while trying to require 'http' from node.
It looks like the package @remix-run/node does not contain any valid esm export. I assume it does fallback to commonjs instead and from there it takes @remix-run/web-fetch in commonjs as well.

Not sure if this is the correct assumption.

markusw@xxx:/tmp/test (main)$ pnpm run dev

> test@ dev /tmp/test
> remix dev --manual


 💿  remix dev

 info  building...
 info  built (797ms)
Error: Dynamic require of "http" is not supported
    at file:https:///tmp/test/build/index.js?t=1695049617985.849:11:9
    at node_modules/.pnpm/@[email protected]/node_modules/@remix-run/web-fetch/dist/lib.node.cjs (file:https:///tmp/test/build/index.js?t=1695049617985.849:4452:16)
    at file:https:///tmp/test/build/index.js?t=1695049617985.849:17:50
    at node_modules/.pnpm/@[email protected][email protected]/node_modules/@remix-run/node/dist/globals.js (file:https:///tmp/test/build/index.js?t=1695049617985.849:5476:20)
    at file:https:///tmp/test/build/index.js?t=1695049617985.849:17:50
    at node_modules/.pnpm/@[email protected][email protected]/node_modules/@remix-run/node/dist/index.js (file:https:///tmp/test/build/index.js?t=1695049617985.849:9751:20)
    at file:https:///tmp/test/build/index.js?t=1695049617985.849:17:50
    at file:https:///tmp/test/build/index.js?t=1695049617985.849:20675:27
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
^C ELIFECYCLE  Command failed.
@KnisterPeter
Copy link
Author

If the assumption above is correct (ESM exports missing) I will try to create a PR which addresses the issue.
Other than that I have no clue why we see commonjs for this in the server bundle if the output is set (and defaults) to ESM.

@mao437303994
Copy link

The 'serverDependenciesToBundle' attribute should not match all.

@Mxs2019
Copy link

Mxs2019 commented Oct 3, 2023

Was anyone able to figure this out? I'm facing the same issue.

@KnisterPeter
Copy link
Author

Not yet

@brettdh
Copy link

brettdh commented Oct 23, 2023

Also ran into this on Remix 2.0.1 when building to deploy to AWS Lambda, using either @remix-run/architect or remix-aws. This error occurred when using remix-aws:

2023-10-23T13:31:32.103Z	undefined	ERROR	Uncaught Exception 	{
    "errorType":"Error",
    "errorMessage":"Dynamic require of \"path\" is not supported",
    "stack":[
        "Error: Dynamic require of \"path\" is not supported",
        "    at file:https:///var/task/ui/build/index.mjs:11:9",
        "    at node_modules/source-map-support/source-map-support.js (file:https:///var/task/ui/build/index.mjs:1082:76)",
        "    at file:https:///var/task/ui/build/index.mjs:17:50",
        "    at node_modules/remix-aws/node_modules/@remix-run/node/dist/index.js (file:https:///var/task/ui/build/index.mjs:9592:29)",
        "    at file:https:///var/task/ui/build/index.mjs:17:50",
        "    at file:https:///var/task/ui/build/index.mjs:31229:27",
        "    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"
    ]
}

or this one when using @remix-run/architect:

2023-10-21T02:21:26.578Z	undefined	ERROR	Uncaught Exception 	{
    "errorType":"Error",
    "errorMessage":"Dynamic require of \"node:crypto\" is not supported",
    "stack":[
        "Error: Dynamic require of \"node:crypto\" is not supported",
        "    at file:https:///var/task/ui/build/index.mjs:11:9",
        "    at node_modules/@remix-run/architect/dist/sessions/arcTableSessionStorage.js (file:https:///var/task/ui/build/index.mjs:87308:19)",
        "    at file:https:///var/task/ui/build/index.mjs:17:50",
        "    at node_modules/@remix-run/architect/dist/index.js (file:https:///var/task/ui/build/index.mjs:87510:34)",
        "    at file:https:///var/task/ui/build/index.mjs:17:50",
        "    at file:https:///var/task/ui/build/index.mjs:107950:32",
        "    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"
    ]
}

Workaround was to bundle the server module as CommonJS by removing "type": "module" from package.json and modifying remix.config.js:

module.exports = {
  ...
  serverBuildPath: "build/index.cjs",
  serverModuleFormat: "cjs",
}

which is not ideal, but works for us for now.

@brettdh
Copy link

brettdh commented Oct 25, 2023

...that is, I thought it worked for us, but instead it results in the issue described here: #7761

brettdh added a commit to brettdh/remix that referenced this issue Oct 26, 2023
Having `type: "module"` in `package.json` along with
`serverDependenciesToBundle: "all"` in `remix.config.js`
causes a build error:

    Error: Dynamic require of "http" is not supported

Oddly, in this integration test, it appears to happen at run time
(unless I'm misreading the stack trace), whereas in the description
of remix-run#7467, the error appears at build time.
@brettdh
Copy link

brettdh commented Nov 6, 2023

This PR repros the bug with a failing integration test: #7779

What else needs to happen for a bug:unverified to become a bug Something isn't working , and what can I do next to help the PR move along?

@fullstackwebdev
Copy link

I tried working on it for a few more hours, I was able to hack remix.run to run in CJS mode but it has issues. Will keep trying.

I found this site:
https://arethetypeswrong.github.io/?p=%40copilotkit%2Freact-core%400.14.0

Screenshot from 2023-12-07 21-41-24

@bartekus
Copy link

The solution to this is as @mao437303994 mentioned, do not use serverDependenciesToBundle: 'all' and instead explicitly define it as and array of specific packages to bundle: serverDependenciesToBundle: ['some-package', 'another-package']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants