remix icon indicating copy to clipboard operation
remix copied to clipboard

`remix dev` & `remix build` don't detect local packages from `pnpm` workspace

Open supachaidev opened this issue 2 years ago • 6 comments

What version of Remix are you using?

1.6.7

Steps to Reproduce

  1. Clone the repo https://github.com/supachaidev/remix-build-cannot-find-module-repo.
  2. Run pnpm i.
  3. Run pnpm dev or pnpm build to see the warning message below in Terminal.
The path "shared-ui" is imported in app/routes/index.tsx but "shared-ui" was not found in your node_modules. Did you forget to install it?

Expected Behavior

The suggesting forget to install it? message should not be present, because there is a symlink to the shared-ui local package in node_modules directory.

Actual Behavior

There is a warning message below when running remix dev or remix build.

The path "shared-ui" is imported in app/routes/index.tsx but "shared-ui" was not found in your node_modules. Did you forget to install it?

supachaidev avatar Jul 31 '22 12:07 supachaidev

Same message with npm workspaces. But application seems to work anyways. (also on Remix 1.6.7, and Windows 10)

Only when I add these lines to the shared component:

  "exports": {
    ".": {
      "import": "./dist/main.js"
    }
  },

Adding the require or default import clears the error/warning again:

  "exports": {
    ".": {
      "import": "./dist/main.js",
      "default": "./dist/main.js"
    }
  },

ngbrown avatar Aug 05 '22 06:08 ngbrown

Having the same issue while using pnpm workspaces

jineshshah36 avatar Sep 21 '22 21:09 jineshshah36

I have a similar issue with yarn link. It seems like Remix is just not respecting symlinks in general?

tyteen4a03 avatar Oct 23 '22 21:10 tyteen4a03

Using pnpm. I'm seeing something slightly different, but related, in dev mode when I load the page:

Warning: You may have a dependency that could be inaccessible in production
  | Please run: npm i .pnpm

R-Bower avatar Oct 26 '22 22:10 R-Bower

Seems related to https://github.com/remix-run/remix/issues/4234

Its definetly symlink related

Update:

Okay its not symlink related

See solution on https://github.com/remix-run/remix/issues/4234#issuecomment-1317549172

You need to specify local packages to be bundled explicitily otherwise remix will assume all files that don't start with ./ or / to be external

dan-cooke avatar Nov 16 '22 18:11 dan-cooke

@supachaidev Please try @dan-cooke's solution and tell us if that was indeed the problem.

machour avatar Jan 22 '23 15:01 machour

@machour, no @dan-cooke's solution does not silence the warning. I forked @supachaidev's example, upgraded all the Remix packages, and set serverDependenciesToBundle to "all". Still seeing the warning when I do this:

(cd apps/my-remix-app && npx remix build)

Repo: https://github.com/stevecaldwell77/remix-build-cannot-find-module-repo

stevecaldwell77 avatar Apr 30 '23 18:04 stevecaldwell77

OK I think i figured out what's going on here. I noticed that I got the warning when I ran this:

npx remix build

But not if I ran it through my package.json's scripts using pnpm, i.e.:

pnpm run build

From looking at serverBareModulesPlugin.js, it's checking the npm_config_user_agent envar to decide whether to warn or not. If you use pnpm run it will set that envar to something that causes the code to skip the warning.

This all seems pretty fragile to me. For my purpose, I'm using the Rush monorepo tool, so I'm doing something like:

rushx build

This is resulting in npm_config_user_agent not being set, so I'm getting the warning, which Rush then treats as a broken build.

I'm hacking it by putting "pnpm run" inside my package.json scripts e.g.

"scripts: {
    "build": "pnpm run build:remix && ...",
}

stevecaldwell77 avatar Apr 30 '23 18:04 stevecaldwell77

Using pnpm. I'm seeing something slightly different, but related, in dev mode when I load the page:

Warning: You may have a dependency that could be inaccessible in production
  | Please run: npm i .pnpm

@R-Bower did you solve this?

lukebars avatar May 01 '23 11:05 lukebars

Any update on solving this issue in local development? It works but the console errors can cause confusion

TheGreatAxios avatar Jun 05 '23 20:06 TheGreatAxios

I'm having the same issue in a project using yarn workspaces. If @remix-run/dev is hoisted into the workspace root it warns about importing a package that isn't hoisted. The project builds and runs fine but the console warning is confusing.

Repo: https://github.com/danphilibin/remix-yarn-workspaces-import

danphilibin avatar Jun 11 '23 19:06 danphilibin

No longer reproducible in Remix @2.0.0-pre.5 .

I cloned the repro, replaced the existing apps/my-remix-app via:

npx create-remix@pre --template https://github.com/remix-run/remix/tree/release-next/templates/remix

Then upgraded all the Remix packages:

pnpm i @remix-run/node@pre @remix-run/react@pre @remix-run/serve@pre @remix-run/dev@pre @remix-run/eslint-config@pre

Finally I added shared-ui as a workspace dep to the app, ran pnpm i and pnpm dev.

pcattori avatar Aug 31 '23 20:08 pcattori