-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Draft: Deep import HTML and non-ESM files with exports and ?url
query
#7097
Draft: Deep import HTML and non-ESM files with exports and ?url
query
#7097
Conversation
…rts w/ query Related to vitejs#6725 which fixed up some cases like `import deepPath from 'resolve-exports-path/deep.js?url'`
@@ -107,6 +116,18 @@ <h2>resolve package that contains # in path</h2> | |||
import deepPath from 'resolve-exports-path/deep.json?url' | |||
text('.exports-deep-query', deepPath) | |||
|
|||
// deep import SVG w/ exports w/ query | |||
import deepSvgPath from 'resolve-exports-path/deep.svg?url' | |||
text('.exports-deep-svg-query', deepSvgPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one works 👍 So we can rule out the problem of it only working with .js
or .json
files
|
||
// deep import non-ESM w/ exports w/ query | ||
import deepNonEsmPath from 'resolve-exports-path/deep-non-esm.js?url' | ||
text('.exports-deep-non-esm-query', deepNonEsmPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without any exports
defined, this kind of thing normally works.
But when exports
is added for the same file, then you start running into errors like:
Uncaught SyntaxError: The requested module '/@fs/C:/Users/MLM/Documents/GitHub/vite/packages/playground/resolve/exports-path/deep-non-esm.js' does not provide an export named 'default'
|
||
// deep import HTML w/ exports w/ query | ||
import deepHtmlPath from 'resolve-exports-path/deep.html?url' | ||
text('.exports-deep-html-query', deepHtmlPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without any exports
defined, this kind of thing normally works.
But when exports
is added for the same file, then you start running into errors like:
[plugin:vite:import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .html file format.
C:/Users/MLM/Documents/GitHub/vite/packages/playground/resolve/exports-path/deep.html:4:19
2 | <html>
3 | <body>
4 | <div>foo</div>
| ^
5 | </body>
6 | </html>
at formatError (C:\Users\MLM\Documents\GitHub\vite\packages\vite\src\node\server\pluginContainer.ts:315:31)
at TransformContext.error (C:\Users\MLM\Documents\GitHub\vite\packages\vite\src\node\server\pluginContainer.ts:305:13)
at TransformContext.transform (C:\Users\MLM\Documents\GitHub\vite\packages\vite\src\node\plugins\importAnalysis.ts:140:14)
at Object.transform (C:\Users\MLM\Documents\GitHub\vite\packages\vite\src\node\server\pluginContainer.ts:583:20)
at doTransform (C:\Users\MLM\Documents\GitHub\vite\packages\vite\src\node\server\transformRequest.ts:156:27
Click outside or fix the code to dismiss.
You can also disable this overlay by setting server.hmr.overlay to false in vite.config.js.
@@ -20,6 +20,20 @@ test('deep import with query with exports field', async () => { | |||
expect(await page.textContent('.exports-deep-query')).not.toMatch('fail') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @sapphi-red since you recently fixed up a super similar and relevant case in #7073, I was curious if you had any insights or hunches about what is additionally going wrong.
(the testing and comments here are done on the latest main
with your fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I noticed that my fiix was broken.
I have made a PR which fixes (#7098).
This would work with .html
and others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapphi-red Thanks for taking a look and proposing a change already!
Deep import HTML and non-ESM files with exports and
?url
queryRelated to #6725 -> #7073 which fixed up some cases like
import deepPath from 'resolve-exports-path/deep.js?url'
Relevant to this discussion: #6459
Fix element-hq/hydrogen-web#686 -> element-hq/hydrogen-web#693
TODO: This is just tracking some tests atm. Still working out a fix.
Dev notes
When using
pnpm run debug-serve
, in order to get the Chromium window with the playwright results to not just close before you can see the results and inspect the devtools console there, add adebugger
statement to theafterAll
hook inscripts/jestPerTestSetup.ts#L162
It would be really nice if those console errors were piped up to the normal Jest logging to see.
The "Debugging" section of the contributing guide doesn't work for me as I don't see the "Javascript Debug Terminal" button in VSCode. Is there supposed to be a
launch.json
somewhere to define what goes on there? Perhaps I need to be on a.js
or.ts
file first but I was onindex.html
for the tests I wanted to debug.Trying to run the test suite on Windows 10, I encountered a problem with symlinks. As suggested by lovell/sharp#1671 (comment), running in a console tab as admin works 🤷
Trying to use
pnpm run debug-serve
, shows me the following error in the devtools console but this can be solved by updating the path forjest
in thepackage.json
, see jestjs/jest#3750 (comment)Fix:
"debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest",
->"debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/jest/bin/jest.js",
Error:
Description
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).