Navigation Menu

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

Vite cannot load configuration files in the link directory #4180

Closed
6 tasks done
yinzhenyu-su opened this issue Jul 9, 2021 · 3 comments · Fixed by #4181
Closed
6 tasks done

Vite cannot load configuration files in the link directory #4180

yinzhenyu-su opened this issue Jul 9, 2021 · 3 comments · Fixed by #4181

Comments

@yinzhenyu-su
Copy link
Contributor

yinzhenyu-su commented Jul 9, 2021

Describe the bug

Failed to package in the linked directory,Because the configuration file was not successfully loaded.

require.extensions[extension] = (module: NodeModule, filename: string) => {
    if (filename === fileName) {
      ;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
    } else {
      defaultLoader(module, filename)
    }
  }

is this code, filename resolves to realpath but the fileName is link path. therefore lead to use defaultLoader to load vite.config.ts which is undefined loader.
so. my fix is use fs.realpathSync to get real fileName dir, and that's work for me.

require.extensions[extension] = (module: NodeModule, filename: string) => {
    if (filename === fs.realpathSync(fileName)) {
      ;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
    } else {
      defaultLoader(module, filename)
    }
  }

Reproduction

  1. Create a vite project directory, the configuration file is vite.config.ts
  2. Execute the following command to link the original directory to the new directory
    cd D:
    mklink /j dir D:\to\source\dir
  3. Perform packaging in link path
    yarn build

System Info

System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz
    Memory: 1.25 GB / 7.89 GB
  Binaries:
    Node: 12.22.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 91.0.4472.124
    Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.64)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    vite: ^2.4.1 => 2.4.1

Used Package Manager

yarn

Logs

failed to load config from D:\editor\vite.config.ts
error during build:
TypeError: defaultLoader is not a function
    at Object.require.extensions.<computed> [as .ts] (D:\Code\xbguan.ppcw_h5\editor2\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:74775:13)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at loadConfigFromBundledFile (D:\Code\xbguan.ppcw_h5\editor2\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:74780:17)
    at loadConfigFromFile (D:\Code\xbguan.ppcw_h5\editor2\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:74696:32)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async resolveConfig (D:\Code\xbguan.ppcw_h5\editor2\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:74282:28)
    at async doBuild (D:\Code\xbguan.ppcw_h5\editor2\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:50882:20)
error Command failed with exit code 1.

Validations

@ZYinMD
Copy link

ZYinMD commented Aug 31, 2021

To make this issue more searchable , the error message in a js project will be (different from ts project):

SyntaxError: Cannot use import statement outside a module

Also, some other keywords: windows, symlink, git-bash, cmd, powershell, junction

This is the same issue as #1493.

@ZYinMD
Copy link

ZYinMD commented Aug 31, 2021

From my test, it doesn't happen in projects created with template vanilla, but does happen with template vue and template react.

@zheeeng
Copy link
Contributor

zheeeng commented Oct 21, 2021

Any progress on it?

@sodatea sodatea added the has pr label Oct 25, 2021
patak-dev pushed a commit that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants