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

Dist file generated in workspace, makes dist unusable #1204

Closed
rossanmol opened this issue Oct 24, 2023 · 1 comment
Closed

Dist file generated in workspace, makes dist unusable #1204

rossanmol opened this issue Oct 24, 2023 · 1 comment
Labels
enhancement ✨ New feature or request

Comments

@rossanmol
Copy link

rossanmol commented Oct 24, 2023

Description

There is this bug inside importBuild.cjs which is generated automatically here:
const { setImportBuildGetters } = await import('${importPath}');,

In NPM workspace, node_modules/vike is located under root directory of the whole monorepo, which causes something of this sort:

const { setImportBuildGetters } = await import('../../../../node_modules/vike/dist/esm/node/runtime/globalContext/loadImportBuild.js');

Instead of resolving the location during build time, this could be modified as follows:

const loc = require.resolve("vike");
const basePath  = loc.split("node_modules/vike")[0];
const { setImportBuildGetters } = await import(`${basePath}node_modules/vike/dist/esm/node/runtime/globalContext/loadImportBuild.js`);

Or even better, loadImportBuild.js could be added to exports in package.json so that it can simply be imported like so:

const loc = require.resolve("vike");
const basePath  = loc.split("node_modules/vike")[0];
const { setImportBuildGetters } = await import('vike/dist/esm/node/runtime/globalContext/loadImportBuild.js');

For now, I am manually updating importBuild.cjs, as otherwise the import is just invalid when dist is deployed without the rest of the monorepo.

@brillout
Copy link
Member

You aren't supposed to move node_modules/ into your production environement (e.g. $ rsync node_modules/ user@remote:/node_modules), instead you're supposed to run $ pnpm install and then $ pnpm run build in your production environment. The path in importBuild.cjs will then be correct.

I undertand this is very limiting (which I find unacceptable) and I'll be working on #562 and #1165 (which will solve the issue) right after the V1 design is out-of-beta.

Closing in favor of #562.

Until #526 is implemented I guess you can continue using your workaround?

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
@brillout brillout added enhancement ✨ New feature or request and removed bug 💥 labels Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants