Closed garth closed 4 months ago
Reverting back to v1.3.4 and there are no ESM warnings and the build works without serverDependenciesToBundle
.
I encountered a similar problem, and the downgrade to v1.3.4 as suggested here was the only fix that worked.
While using v1.4.1, here's what I observed:
serverDependenciesToBundle
to get my builds passing
@apollo
dependenciesCannot find module
pattern:
date-fns
as a dependency to satisfy A's peerdate-fns
as a dev + peer dependencyCannot find module: date-fns
at runtime and fails to startReverting to v1.3.4 (without magic remix
package) works fine.
š hey @garth and @sdalonzo can one of you create a simple reproducible stackblitz, codesandbox, or pr using the bug report for me š
Hey @mcansh, I created a repo with a new Remix project to reproduce the issue that @sdalonzo reported. This commit shows how installing @apollo/client
and using one of its exports produces the warning that recommends adding it to serverDependenciesToBundle
, which then requires adding more entries to serverDependenciesToBundle
.
I have a script that will find all the ESM packages for you. https://github.com/kiliman/rmx-cli#-get-esm-packages
āÆ rmx get-esm-packages @apollo/client
š¦ @apollo/client
š¦ ts-invariant
š¦ zen-observable-ts
šØ Add the following dependencies to your serverDependenciesToBundle
"@apollo/client",
"ts-invariant",
"zen-observable-ts"
awesome @kiliman! our current serverDependenciesToBundle
only looks at bundling the explicit (or regex) dependency, so you'll have to also add any transitive dependencies as well
I can't believe I need to include all the transitive dependencies! That's a huge list. Could we make this more smooth?
(Below only shows the result of one of my deps.)
āÆ npx rmx-cli get-esm-packages "@milkdown/core"
š¦ @milkdown/core
š¦ @milkdown/ctx
š¦ @milkdown/exception
š¦ @milkdown/transformer
š¦ remark
š¦ remark-parse
š¦ mdast-util-from-markdown
š¦ decode-named-character-reference
š¦ character-entities
š¦ mdast-util-to-string
š¦ micromark
š¦ micromark-core-commonmark
š¦ micromark-factory-destination
š¦ micromark-util-character
š¦ micromark-util-symbol
š¦ micromark-util-types
š¦ micromark-factory-label
š¦ micromark-factory-space
š¦ micromark-factory-title
š¦ micromark-factory-whitespace
š¦ micromark-util-chunked
š¦ micromark-util-classify-character
š¦ micromark-util-html-tag-name
š¦ micromark-util-normalize-identifier
š¦ micromark-util-resolve-all
š¦ micromark-util-subtokenize
š¦ micromark-util-combine-extensions
š¦ micromark-util-decode-numeric-character-reference
š¦ micromark-util-encode
š¦ micromark-util-sanitize-uri
š¦ micromark-util-decode-string
š¦ unist-util-stringify-position
š¦ unified
š¦ bail
š¦ trough
š¦ vfile
š¦ vfile-message
š¦ remark-stringify
š¦ mdast-util-to-markdown
š¦ longest-streak
š¦ unist-util-visit
š¦ unist-util-is
š¦ unist-util-visit-parents
š¦ zwitch
š¦ @milkdown/design-system
šØ Add the following dependencies to your serverDependenciesToBundle
"@milkdown/core",
"@milkdown/ctx",
"@milkdown/design-system",
"@milkdown/exception",
"@milkdown/transformer",
"bail",
"character-entities",
"decode-named-character-reference",
"longest-streak",
"mdast-util-from-markdown",
"mdast-util-to-markdown",
"mdast-util-to-string",
"micromark",
"micromark-core-commonmark",
"micromark-factory-destination",
"micromark-factory-label",
"micromark-factory-space",
"micromark-factory-title",
"micromark-factory-whitespace",
"micromark-util-character",
"micromark-util-chunked",
"micromark-util-classify-character",
"micromark-util-combine-extensions",
"micromark-util-decode-numeric-character-reference",
"micromark-util-decode-string",
"micromark-util-encode",
"micromark-util-html-tag-name",
"micromark-util-normalize-identifier",
"micromark-util-resolve-all",
"micromark-util-sanitize-uri",
"micromark-util-subtokenize",
"micromark-util-symbol",
"micromark-util-types",
"remark",
"remark-parse",
"remark-stringify",
"trough",
"unified",
"unist-util-is",
"unist-util-stringify-position",
"unist-util-visit",
"unist-util-visit-parents",
"vfile",
"vfile-message",
"zwitch"
I'm running into this now. My serverless file was just kind of bundling the entire node_modules but apparently I did something that made that too big. I'm pretty sure the real bundle size is less than 5MB but hard to say since I can't get it to build properly. Currently I'm having to tediously build -> upload -> run app -> check error logs for missing dependency.
The script has been useful for some libraries but there's quite a few outliers that it doesn't catch. Any potential updates or improvements coming to make this easier?
ESM is the future, not the present. Until then, the workaround Iām using is to bundle the libraries I use in the Remix app, along with all the transitive dependencies, into a single-file CommonJS module (I use tsup
to generate such bundle), so that they can be correctly loaded into a Remix app until they fix this gotcha.
I hope Remix team fixes this issue soon. I spent many hours scratching my head over this and I was so close to migrating the app to Astro (which does not have any issue with ESM dependencies).
I'm getting
yargs-parser is possibly an ESM only package and should be bundled with "serverDependenciesToBundle" in remix.config.js.
even though I'm using it in an action.
Am I doing something wrong?
It seems this is fixed by https://github.com/remix-run/remix/pull/6916
@pcattori Can your confirm?
It seems this is fixed by #6916
@pcattori Can your confirm?
Yes, plus serverDependenciesToBundle
is no longer a supported API with Remix Vite. You should instead use Vite's ssr.noExternal
option as described in the ESM/CJS troubleshooting docs
What version of Remix are you using?
1.4.1
Steps to Reproduce
When a warning is shown that a package needs to be added to
serverDependenciesToBundle
, I add the package the config. But then the build fails on every other dependency with "Cannot find module".Removing the
serverDependenciesToBundle
from the config fixes the build but shows ESM warnings.I am installing dependencies with pnpm.
Expected Behavior
Adding
serverDependenciesToBundle
to config should remove ESM warnings and not break the build.Actual Behavior
Adding
serverDependenciesToBundle
to config does fix the ESM warnings, but causes build to fail.