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: dynamic import path contain ../ and its own directory #9350

Merged
merged 7 commits into from
Aug 16, 2022

Conversation

Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Jul 25, 2022

Description

fix: #9265

I think it should work properly

Additional context


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 p2-edge-case Bug, but has workaround or limited in scope (priority) label Jul 25, 2022
@Dunqing
Copy link
Contributor Author

Dunqing commented Jul 28, 2022

Does anyone know why the test information is omitted?
image

@Dunqing
Copy link
Contributor Author

Dunqing commented Jul 28, 2022

Does anyone know why the test information is omitted? image

The same problem is present in the vitest VSCODE extension

image

@ahnpnl
Copy link

ahnpnl commented Aug 16, 2022

Hi, are there any updates about this fix?

Comment on lines +111 to +118
let newRawPattern = posix.relative(
posix.dirname(importer),
await toAbsoluteGlob(rawPattern, root, importer, resolve)
)

if (!/^\.{1,2}\//.test(newRawPattern)) {
newRawPattern = `./${newRawPattern}`
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this logic, do we have enough tests for all cases here?
If importer is /root/dir/nested/importer.js and toAbsoluteGlob returns /root/foo/bar/{pattern}.js, then newRawPattern ends up being ./../foo/bar/{pattern}.js 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Ah, no.. I missed the !. Ok, now I understand 😄

@patak-dev patak-dev changed the title fix: dynamic import path contain ../ and its own directory will not work fix: dynamic import path contain ../ and its own directory Aug 16, 2022
@patak-dev patak-dev merged commit c6870f3 into vitejs:main Aug 16, 2022
@zyakita
Copy link

zyakita commented Sep 1, 2022

I still have a build error (Heroku)

-----> Build
       Running build (yarn)
       yarn run v1.22.19
       $ vite build
       vite v3.0.9 building for production...
       transforming...
       ✓ 82 modules transformed.
Could not resolve '../../hooks/useIsSignedIn' from src/components/hocs/AuthProtected.jsx
error during build:
Error: Could not resolve '../../hooks/useIsSignedIn' from src/components/hocs/AuthProtected.jsx
    at error (file:///tmp/build_370de0e6/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at ModuleLoader.handleResolveId (file:///tmp/build_370de0e6/node_modules/rollup/dist/es/shared/rollup.js:22333:24)
    at file:///tmp/build_370de0e6/node_modules/rollup/dist/es/shared/rollup.js:22296:26
error Command failed with exit code 1.
       info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@patak-dev
Copy link
Member

@zyakita please create a new issue against the latest version of Vite with a minimal reproduction. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v3 import() and v2 import() behavior is inconsistent
6 participants