remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.89k stars 2.52k forks source link

getDependenciesToBundle can't find dependencies of ESM package #5309

Open nimaa77 opened 1 year ago

nimaa77 commented 1 year ago

What version of Remix are you using?

1.11.1

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

Steps to Reproduce

in remix.config.js file import getDependenciesToBundle package and pass an ESM package to it

const { getDependenciesToBundle } = require("@remix-run/dev");

/**
 * @type {import('@remix-run/dev').AppConfig}
 */
module.exports = {
  cacheDirectory: "./node_modules/.cache/remix",
  ignoredRouteFiles: ["**/.*", "**/*.css", "**/*.test.{js,jsx,ts,tsx}"],
  serverDependenciesToBundle: [...getDependenciesToBundle("@uiw/react-md-editor")],
};

run build script

Expected Behavior

to bundle all ESM dependencies and of the passed in dependency the app and start the app without any errors

Actual Behavior

Online Playground: https://stackblitz.com/edit/node-cytlj4?file=app/routes/index.tsx

during the build these get printed on the screen:

/Users/nima/projects/my-remix-app/node_modules/package.json does not exist
rehype is possibly an ESM only package and should be bundled with "serverDependenciesToBundle in remix.config.js.
rehype-prism-plus is possibly an ESM only package and should be bundled with "serverDependenciesToBundle in remix.config.js.

and when start the app using dev command

/Users/nima/projects/my-remix-app/node_modules/@uiw/react-markdown-preview/lib/index.js:13
var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
                                            ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/nima/projects/my-remix-app/node_modules/react-markdown/index.js from /Users/nima/projects/my-remix-app/node_modules/@uiw/react-markdown-preview/lib/index.js not supported.
Instead change the require of /Users/nima/projects/my-remix-app/node_modules/react-markdown/index.js in /Users/nima/projects/my-remix-app/node_modules/@uiw/react-markdown-preview/lib/index.js to a dynamic import() which is available in all CommonJS modules.
lucaashrq commented 1 year ago

Did you fix it? I got same issue.

0xtlt commented 1 year ago

I still have this issue with the same configuration

lifeiscontent commented 1 year ago

ran into this as well, it seems like a node issue potentially I opened an issue here: https://github.com/remarkjs/react-markdown/issues/766 but the remarkjs team thinks its a remix issue, though I'm not so sure.