Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_PACKAGE_PATH_NOT_EXPORTED with dev server in v0.21.8 #1056

Closed
rmarscher opened this issue Dec 10, 2024 · 11 comments · Fixed by #1064
Closed

ERR_PACKAGE_PATH_NOT_EXPORTED with dev server in v0.21.8 #1056

rmarscher opened this issue Dec 10, 2024 · 11 comments · Fixed by #1064
Labels
bug Something isn't working

Comments

@rmarscher
Copy link
Collaborator

Example error - Package subpath './router/client.js?v=73b27883' is not defined by "exports"

This patch fixes it for me:

--- a/dist/lib/middleware/dev-server-impl.js
+++ b/dist/lib/middleware/dev-server-impl.js
@@ -136,7 +136,7 @@ const createMainViteServer = (env, configPromise)=>{
         }
         if (file === 'waku' || file.startsWith('waku/')) {
             // HACK `external: ['waku']` doesn't do the same
-            return import(/* @vite-ignore */ file);
+            return import(/* @vite-ignore */ file.split('.')[0]);
         }
         const vite = await vitePromise;
         if (idOrFileURL.startsWith('file://') && idOrFileURL.includes('/node_modules/')) {
@dai-shi
Copy link
Member

dai-shi commented Dec 10, 2024

I'll look into it. Is it possible to reproduce this with modifying the template a little bit?

@dai-shi
Copy link
Member

dai-shi commented Dec 11, 2024

@dai-shi dai-shi added the bug Something isn't working label Dec 13, 2024
@rmarscher
Copy link
Collaborator Author

Just to confirm, does reverting this line fix your issue? https://github.com/dai-shi/waku/pull/1048/files#diff-11b6fc682384040382e2a82f9bb4b98d7357aa85df2353a660ee6c4488a338c9L145-R145

That does not seem to work. If I log the import, it's this with idOrFileURL:

file:///path/to/waku/project/node_modules/waku/dist/minimal/client.js?v=466ecaf7

which causes an error:

Error: Missing Root component
at Slot (file:///path/to/waku/project/node_modules/waku/dist/minimal/client.js?v=466ecaf7:191:15)

With file.split('.')[0], it's waku/minimal/client and that is working.

@rmarscher
Copy link
Collaborator Author

OK... instead of splitting on the . char, how about this?

--- a/dist/lib/middleware/dev-server-impl.js
+++ b/dist/lib/middleware/dev-server-impl.js
@@ -132,7 +132,7 @@ const createMainViteServer = (env, configPromise)=>{
     const loadServerModuleMain = async (idOrFileURL)=>{
         let file = idOrFileURL.startsWith('file://') ? fileURLToFilePath(idOrFileURL) : idOrFileURL;
         if (file.startsWith(wakuDist)) {
-            file = 'waku' + file.slice(wakuDist.length).replace(/\.\w+$/, '');
+            file = 'waku' + file.slice(wakuDist.length).replace(/\.\w+(?:\?v=\w+)?$/, '');
         }

@dai-shi
Copy link
Member

dai-shi commented Dec 13, 2024

Thanks for looking into it. Splitting with . is fine. I was curious if it has ever worked before.
How can I reproduce it? I would like to write a test.

@dai-shi
Copy link
Member

dai-shi commented Dec 13, 2024

This is reproduced when I'm trying #1012.

@dai-shi
Copy link
Member

dai-shi commented Dec 13, 2024

This is reproduced when I'm trying #1012.

Oops, that was my misunderstanding.

So, I'm still interested in how to reproduce this error and adding a test.

@rmarscher
Copy link
Collaborator Author

I think this is from running in a monorepo.

Create a new folder. Add a package.json file with this:

{
  "name": "my-monorepo",
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}

Add a pnpm-workspace.yaml file with this:

packages:
  - 'packages/*'
cd packages
pnpm create waku@latest
cd waku-project
pnpm run dev

In loadServerModuleMain, since my node_modules is outside the root of the waku project, it includes the full system root path in the request to load the module.

That matches the file.startsWith(wakuDist) condition which drops the path to the waku module folder which then causes it to match the next file.startsWith('waku/') conditional.

With not in a monorepo, the file variable starts with node_modules and not the full system path, so it doesn't match wakuDist and it doesn't start with waku/, so it hits the part where it includes /node_modules which splits on the ? and gets the correct path to import.

@dai-shi
Copy link
Member

dai-shi commented Dec 13, 2024

I think this is from running in a monorepo.

I see. Maybe we should add a spec with a monorepo.

#684 was closed as it's a bit stale, but something like that should be possible. Would you like to give a try? Or, maybe we look for someone who can help.

@dai-shi dai-shi reopened this Dec 13, 2024
@rmarscher
Copy link
Collaborator Author

rmarscher commented Dec 16, 2024

I should be able to find a moment to create a monorepo e2e spec this week. 👍

@rmarscher
Copy link
Collaborator Author

I pushed #1079 to track creating a monorepo spec. I think we can go ahead and close this issue and track that effort there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants