Closed A-Shleifman closed 1 year ago
Same issue with 2.0.0-beta.9
@A-Shleifman Did you find a workaround / know a previous version that worked?
System:
OS: Windows 10 10.0.19044
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Memory: 38.72 GB / 63.75 GB
Binaries:
Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 - C:\Program Files\nodejs\yarn.CMD
npm: 9.1.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.54)
Internet Explorer: 11.0.19041.1566
npmPackages:
@crxjs/vite-plugin: ^2.0.0-beta.9 => 2.0.0-beta.9
vite: ^4.0.2 => 4.0.2
const distPath = '/src/utils/index.ts.js';
await import(distPath);
This goes around Vite (which is bad) and it works, BUT only if this file has already been transpiled before. Any changes to this file and descendants will never be loaded even after a restart. This wouldn't work even as a temporary solution.
@A-Shleifman I was able to find the source of the issue. You can have a look at my fork https://github.com/crxjs/chrome-extension-tools/compare/main...lionelhorn:chrome-extension-tools:86cd570b7a46fcf551df7faf745e7a3a568ddb26
Thank you, @lionelhorn, for looking into this and finding a way to fix the problem. I dug a bit deeper and apparently it's caused by an inconsistency/bug in the lexer. I opened an issue.
Regarding your fork:
1) It looks like your editor is not respecting the project's prettier config.
2) I saw another PR which was trying to solve the same (posix) issue a while ago. https://github.com/crxjs/chrome-extension-tools/pull/474
3) The line new URL(_id.slice(PREFIX.length))
makes the build fail
Do you mind if we merge the fix for this issue separately from the posix fix?
Thanks @A-Shleifman for digging deeper.
- It looks like your editor is not respecting the project's prettier config.
Indeed, realized that prettier issue after the fact. I didn't have time to do a proper PR at the time, that's why I only linked my fork for hints to those interesed.
- I saw another PR which was trying to solve the same (posix) issue a while ago. fixed build vite-plugin on windows (fix #473) #474
I've seen that PR. That's what I added dirtily on top of https://github.com/crxjs/chrome-extension-tools/commit/7342ff05c0796431e3f0e919372a7a8a33146550
- The line
new URL(_id.slice(PREFIX.length))
makes the build fail
Didn't get a chance to test the modifications outside of windows. Build succeeded on windows after the code change but may have broken build for others.
If it helps, this is the error I got when building your fork on my mac:
[!] (plugin bundleClientCode) TypeError: Could not load client//Users/redacted/chrome-extension-tools/packages/vite-plugin/src/client/es/hmr-client-worker.ts (imported by src/node/plugin-background.ts): Invalid URL
TypeError: Could not load client//Users/redacted/chrome-extension-tools/packages/vite-plugin/src/client/es/hmr-client-worker.ts (imported by src/node/plugin-background.ts): Invalid URL
at new NodeError (node:internal/errors:387:5)
at URL.onParseError (node:internal/url:564:9)
at new URL (node:internal/url:640:5)
at Object.load (/Users/redacted/chrome-extension-tools/packages/vite-plugin/rollup.config.ts:68:21)
at /Users/redacted/chrome-extension-tools/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/shared/rollup.js:22841:40
@jacksteamdev, can we merge #630?
Build tool
Vite
Where do you see the problem?
Describe the bug
CRXJS breaks dynamic imports by removing "" around imports
input
output
Imports should be wrapped in quotes, otherwise, they don't work. These imports work when the project is launched with Vite without CRXJS.
Reproduction
Example provided above
Logs
No response
System Info
Severity
blocking an upgrade