remix
remix copied to clipboard
1.4.0 breaks module resolution for linked modules
What version of Remix are you using?
1.4.0
Steps to Reproduce
- Create a new remix project using Remix 1.4.0
- Create a new npm package locally. I'm calling it
my-module
for purposes of documentation in this ticket, but the name doesn't matter. - Import your new local package (
my-module
) somewhere in the new remix project (I put it in the index route). - run
npm link
in your new module directory - run
npm link my-module
in your remix project. - Build the Remix project with
npm run dev
, and the dev build should fail.
Expected Behavior
Local packages installed with npm link
or from a local file path should both be resolved correctly. Instead, the module resolution fails.
Actual Behavior
NPM packages installed with npm link
or from a local file path are not resolved correctly. Attempting to build a remix project with linked modules produces the following error:
✘ [ERROR] [plugin server-bare-modules] Couldn't resolve the base path of "my-module". Searched inside the resolved main file path "/Users/.../my-module/index.js" using "node_modules/my-module"
Additional notes:
- I've tracked down the source of the issue to a few recent changes to
packages/remix-dev/compiler/plugins/serverBareModulesPlugin.ts
. These are listed in the "Related PRs" section.- in
resolveModuleBasePath()
, the plugin compares the output ofrequire.resolve('my-module')
with a search string that includesnode_modules
, and throws an error if they don't match. - When installing a package with
npm link
,require.resolve('some-linked-module')
returns the absolute path to the linked module, rather than the path to the symlink, so the path we're comparing doesn't containnode_modules
and improperly triggers the error.
- in
- Replacing "searchForPathSection =
node_modules${path.sep}${mod}
;" with "searchForPathSection =${path.sep}${mod}
" solves this particular issue, but I don't know if that change will create issues when resolving other non-standard imports. - I'd submit a PR with a failing test as recommended, but I'm not sure how generate a text fixture with a symlinked npm package to reproduce this, and haven't had too much time to dig into that yet.
Related PRs
- #2694
- #2767
#Related Issues
- https://github.com/remix-run/remix/issues/2836 (looks like it's describing the same problem, or at least something similar)
Hey @deimyts, is this still a problem with latest remix version?
I am on the latest version of remix (1.11.1) and can confirm I am experiencing this issue currently.