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(optimize-deps): don't externalize JS files imported with asset extensions #16242

Conversation

proc07
Copy link
Contributor

@proc07 proc07 commented Mar 23, 2024

Description

fix #16116 importing a CommonJS module installed from NPM. The modue contains files with filenames like PeoplePicker.scss.js. These are JavaScript files, obviously, but the filename contains scss.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Copy link

stackblitz bot commented Mar 23, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@proc07 proc07 closed this Mar 23, 2024
@proc07 proc07 reopened this Mar 23, 2024
@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: deps optimizer Esbuild Dependencies Optimization labels Mar 24, 2024
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks. Would you add a test case in playground/optimize-deps?

@proc07
Copy link
Contributor Author

proc07 commented Mar 24, 2024

Thanks. Would you add a test case in playground/optimize-deps?

sure, I'll add a test case

@proc07
Copy link
Contributor Author

proc07 commented Mar 24, 2024

@sapphi-red hi, I have submitted the test code, but how does the Actions check failing

@sapphi-red
Copy link
Member

I guess you forgot to run pnpm i after adding a local package.

@sapphi-red sapphi-red changed the title fix: externalize the asset js file type, but enter vite:dep-pre-bundle fix(optimize-deps): don't externalize JS files imported with asset extensions Mar 27, 2024
Comment on lines 157 to +159
if (kind === 'require-call') {
// #16116 fix: Import the module.scss path, which is actually module.scss.js
if (resolved.endsWith('.js')) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we only check this in require-call only? Wouldn't this help for imports too?

Copy link
Member

Choose a reason for hiding this comment

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

I think the reason is because we don't support import without extensions in dependencies. But I've noticed that there's a case like import 'normalize.css'.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, you have to specify the full path with imports. Let's try this then.

@sapphi-red sapphi-red merged commit 4161843 into vitejs:main May 30, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when importing CommonJS module that contains files like module.scss.js
3 participants