Skip to content

Commit

Permalink
suggest dynamic import() as a viable alternative to importing ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth authored Apr 23, 2023
1 parent 605b580 commit e2e7e92
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/pages/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ module.exports = {
};
```

In rare circumstances, some Node.js packages are ESM-only and does not work properly when bundled. In such cases, you can use dynamic import to import the module. For example:

```js filename=index.js
export const loader = async (args: LoaderArgs) => {
const lib = await import('that-esm-only-lib-that-shall-not-be-bundled')
return lib.handleRequest(args.request)
}
```

> Why does this happen?
Remix compiles your server build to CJS and doesn't bundle your node modules. CJS modules can't import ESM modules.
Expand Down

0 comments on commit e2e7e92

Please sign in to comment.