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

目录中只要存在node_modules,无法正常运行 #17903

Closed
7 tasks done
myPc1994 opened this issue Aug 20, 2024 · 4 comments
Closed
7 tasks done

目录中只要存在node_modules,无法正常运行 #17903

myPc1994 opened this issue Aug 20, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@myPc1994
Copy link

myPc1994 commented Aug 20, 2024

Describe the bug

在项目的上级目录中只要存在node_modules,那么CommonJS 导入的就无法正常解析
1.在项目中,我导入两个包一个是axios一个是dayjs(在其他项目中导入了其他包也是如此,这里为了最小化展示就导入两个包)
2.当上级目录出现node_modules目录的时候,就如下图所示
3.尝试代码一个不变的将其移到上级总没有node_modules的目录下,就正常运行了
4.由于这是目录问题,无法在stackblitz中提供示例

QQ20240820-083736
QQ20240820-084447
QQ20240820-083758

Reproduction

https://stackblitz.com/edit/vitejs-vite-pcpxok?file=index.html&terminal=dev

Steps to reproduce

1.正常的使用vite安装vue-ts :yarn create vite my-vue-app --template vue-ts
2.导入包dayjs: yarn add dayjs
3. 在main.js中使用dayjs: import dayjs from "dayjs"
4. 正常运行项目:yarn dev
5. 到这里就出现问题了

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
    Memory: 8.27 GB / 15.86 GB
  Binaries:
    Node: 20.11.1 - D:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - D:\nodejs\npm\yarn.CMD
    npm: 10.2.4 - D:\Program Files\nodejs\npm.CMD
    pnpm: 9.4.0 - D:\nodejs\npm\pnpm.CMD

Used Package Manager

npm

Logs

[vite] connecting...
client:614 [vite] connected.
main.ts:8 Uncaught SyntaxError: The requested module '/node_modules/dayjs/dayjs.min.js?v=4c94d2c5' does not provide an export named 'default' (at main.ts:8:8)

Validations

Copy link

stackblitz bot commented Aug 20, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@coderwei99
Copy link
Contributor

I don't think the parent directory should contain node_modules, which would be confusing

@myPc1994
Copy link
Author

I don't think the parent directory should contain node_modules, which would be confusing
我有个需求需要将其放到node_modules中运行,但是经过长时间排除后,发现了这个问题,很多包都会报错误SyntaxError: The requested module ‘xxxxxx' does not provide an export named 'default'

@sapphi-red
Copy link
Member

Dupcalite of #17467

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Aug 20, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants