crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.75k stars 182 forks source link

vite-plugin will not build on Windows #521

Open MaxterBattle opened 1 year ago

MaxterBattle commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

Attempting to build vite-plugin on windows fails with some path related error.

It appears this is something in rollup.config.ts that is mixing windows and posix paths together. Specifically expressions like: path.posix.resolve(__dirname, "src/node/$1") may misbehave on Windows because the __dirname variable contains a windows style path, e.g. C:\Max\chrome-extension-tools\packages\vite-plugin.

Reproduction

ON WINDOWS load the monorepo for chrome-extension-tools. pnpm install cd package/vite-plugin (cd is C:\Max\chrome-extension-tools\packages\vite-plugin) pnpm run build

Error message cites a syntactically invalid path with a C:\ in the middle:

/Max/chrome-extension-tools/packages/vite-plugin/C:\Max\chrome-extension-tools\packages\vite-plugin/src/client/html/precontroller.html?client

Logs

> @crxjs/vite-plugin@1.0.14 build C:\Max\chrome-extension-tools\packages\vite-plugin
> run-s build:clean build:js

> @crxjs/vite-plugin@1.0.14 build:clean C:\Max\chrome-extension-tools\packages\vite-plugin
> rimraf dist

> @crxjs/vite-plugin@1.0.14 build:js C:\Max\chrome-extension-tools\packages\vite-plugin
> rollup -c rollup.config.ts --configPlugin esbuild

src/node/index.ts → dist/index.mjs, dist/index.cjs...
[!] (plugin bundleClientCode) Error: Could not load /Max/chrome-extension-tools/packages/vite-plugin/C:\Max\chrome-extension-tools\packages\vite-plugin/src/client/html/precontroller.html?client (imported by src/node/plugin-fileWriter--pages.ts): ENOENT: no such file or directory, open 'C:\Max\chrome-extension-tools\packages\vite-plugin\C:\Max\chrome-extension-tools\packages\vite-plugin\src\client\html\precontroller.html'
Error: Could not load /Max/chrome-extension-tools/packages/vite-plugin/C:\Max\chrome-extension-tools\packages\vite-plugin/src/client/html/precontroller.html?client (imported by src/node/plugin-fileWriter--pages.ts): ENOENT: no such file or directory, open 'C:\Max\chrome-extension-tools\packages\vite-plugin\C:\Max\chrome-extension-tools\packages\vite-plugin\src\client\html\precontroller.html'

 ELIFECYCLE  Command failed with exit code 1.
ERROR: "build:js" exited with 1.
 ELIFECYCLE  Command failed with exit code 1.

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (20) x64 Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz
    Memory: 16.10 GB / 31.90 GB
  Binaries:
    Node: 18.5.0 - ~\AppData\Local\nodejs\node.EXE
    Yarn: 1.22.15 - ~\AppData\Local\nodejs\yarn.CMD
    npm: 8.13.2 - ~\AppData\Local\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.521.0), Chromium (105.0.1343.53)
    Internet Explorer: 11.0.22621.1

Severity

annoyance

MaxterBattle commented 1 year ago

This may be a dup of #473. PR #474 is supposed to fix it, but seems stalled.