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

fix(vite): provide correct root directory when building a root project #19298

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Sep 22, 2023

There is an issue where our Vite executors are passing '' as the root directory to Vite, which results in it not finding package.json to detect type: 'module'. This means that root apps which use ESM-only packages will fail to build.

You can see the issue here: https://github.com/jaysoo/nx-vite-root-issue

> nx run root-app:serve:development

failed to load config from /private/tmp/vite1/vite.config.ts
Error [ERR_REQUIRE_ESM]: require() of ES Module /private/tmp/vite1/foo/index.js from /private/tmp/vite1/vite.config.ts not supported.
Instead change the require of index.js in /private/tmp/vite1/vite.config.ts to a dynamic import() which is available in all CommonJS modules.
    at _require.extensions.<computed> [as .js] (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:64527:17)
    at Object.<anonymous> (/private/tmp/vite1/vite.config.ts:36:26)
    at _require.extensions.<computed> [as .js] (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:64524:24)
    at loadConfigFromBundledFile (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:64532:21)
    at async loadConfigFromFile (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:64388:28)
    at async resolveConfig (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:63993:28)
    at async _createServer (file:///private/tmp/vite1/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:63274:20)
    at async viteDevServerExecutor (/private/tmp/vite1/node_modules/@nx/vite/src/executors/dev-server/dev-server.impl.js:34:24)
    at async getLastValueFromAsyncIterableIterator (/private/tmp/vite1/node_modules/nx/src/utils/async-iterator.js:13:19)
    at async iteratorToProcessStatusCode (/private/tmp/vite1/node_modules/nx/src/command-line/run/run.js:41:29)
    at async handleErrors (/private/tmp/vite1/node_modules/nx/src/utils/params.js:9:16)
    at async process.<anonymous> (/private/tmp/vite1/node_modules/nx/bin/run-executor.js:59:28) {
  code: 'ERR_REQUIRE_ESM'
}

Current Behavior

Expected Behavior

Related Issue(s)

Fixes #

@jaysoo jaysoo requested a review from a team as a code owner September 22, 2023 15:16
@vercel
Copy link

vercel bot commented Sep 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Sep 22, 2023 4:09pm

Copy link
Contributor

@ndcunningham ndcunningham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jaysoo jaysoo force-pushed the fix/vite-root-dir branch 2 times, most recently from 7ceb865 to 7c94075 Compare September 22, 2023 15:54
@jaysoo jaysoo merged commit 94d8356 into nrwl:master Sep 22, 2023
2 checks passed
@jaysoo jaysoo deleted the fix/vite-root-dir branch September 22, 2023 17:08
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants