Skip to content

Comments

fix: remove buildTimeImportMetaUrl#8785

Merged
patak-dev merged 3 commits intovitejs:mainfrom
sapphi-red:fix/remove-build-time-import-meta
Jun 26, 2022
Merged

fix: remove buildTimeImportMetaUrl#8785
patak-dev merged 3 commits intovitejs:mainfrom
sapphi-red:fix/remove-build-time-import-meta

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Jun 25, 2022

Description

This error happens for almost all users.

Error: cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: D:\documents\GitHub\vite\packages\vite\dist\client\client.mjs

This does not happen only for a user which is using self-built Vite and the generated dist directory is not removed.

It is p5 but since #8743 is not released yet, a new release is not urgent.

refs #8743
refs vitejs/vite-ecosystem-ci#83

Additional context

export const VITE_PACKAGE_DIR = resolve(
fileURLToPath(import.meta.url),
'../../..'
)
export const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs')
export const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs')
export const CLIENT_DIR = path.dirname(CLIENT_ENTRY)

function testCaseInsensitiveFS() {
if (!CLIENT_ENTRY.endsWith('client.mjs')) {
throw new Error(
`cannot test case insensitive FS, CLIENT_ENTRY const doesn't contain client.mjs`
)
}
if (!fs.existsSync(CLIENT_ENTRY)) {
throw new Error(
'cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: ' +
CLIENT_ENTRY
)
}
return fs.existsSync(CLIENT_ENTRY.replace('client.mjs', 'cLiEnT.mjs'))
}
export const isCaseInsensitiveFS = testCaseInsensitiveFS()

This is the code throwing the error.

Also IIUC a code like this will be broken if it is replaced on build time.

const _require = createRequire(import.meta.url)


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added the p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Jun 25, 2022
@netlify
Copy link

netlify bot commented Jun 25, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit 9ae412d
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62b7a4660aec7e000810fbe6

@sapphi-red sapphi-red marked this pull request as ready for review June 26, 2022 00:14
@sapphi-red
Copy link
Member Author

pnpm test-build-legacy-cjs passed in my local.

@sapphi-red sapphi-red added this to the 3.0 milestone Jun 26, 2022
@patak-dev
Copy link
Member

Since the bug is fixed, we can remove this workaround. @sodatea let us know if you think something should still be done here.

@patak-dev patak-dev merged commit cd32095 into vitejs:main Jun 26, 2022
@sapphi-red sapphi-red deleted the fix/remove-build-time-import-meta branch June 26, 2022 13:34
@haoqunjiang
Copy link
Member

I think in the end, we'll still need the plugin. Resolving import.meta.env at runtime makes its behavior implicitly dependent on the chunk layout. Such implicit dependency doesn't look good for long-term maintenance.
I'll find a better way to fix it, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants