aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
541 stars 47 forks source link

Unable to build #104

Closed RC-14 closed 1 year ago

RC-14 commented 1 year ago

Summary

I manually created a project but when I tried to run it with vite dev or build it with vite build I got an error:

failed to load config from /Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/vite.config.ts
error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/web-ext/lib/util/logger.js from /Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite-plugin-web-extension/dist/index.cjs not supported.
Instead change the require of logger.js in /Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite-plugin-web-extension/dist/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at _require.extensions.<computed> [as .js] (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:64435:17)
    at Object.<anonymous> (/Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite-plugin-web-extension/dist/index.cjs:759:28)
    at _require.extensions.<computed> [as .js] (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:64435:17)
    at Object.<anonymous> (/Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/vite.config.ts:37:48)
    at _require.extensions.<computed> [as .js] (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:64432:24)
    at loadConfigFromBundledFile (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:64440:21)
    at async loadConfigFromFile (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:64296:28)
    at async resolveConfig (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:63904:28)
    at async _createServer (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/chunks/dep-a178814b.js:63190:20)
    at async CAC.<anonymous> (file:///Users/rc-14/Desktop/vite-plugin-web-extension-bug-report/node_modules/vite/dist/node/cli.js:733:24)

This can be fixed by adding "type": "module" to the package.json which I noticed when I looked at the templates.

Reproduction

  1. Clone the following repo: https://github.com/RC-14/vite-plugin-web-extension-bug-report
  2. Get the dependencies: npm i
  3. Run npm run dev or npm run build

Environment

System:
  OS: macOS 13.3.1
  CPU: (8) arm64 Apple M1
  Memory: 72.59 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.16.0 - /opt/homebrew/opt/node@18/bin/node
  Yarn: 1.22.19 - /opt/homebrew/bin/yarn
  npm: 9.5.1 - /opt/homebrew/opt/node@18/bin/npm
Browsers:
  Brave Browser: 112.1.50.121
  Firefox: 112.0.2
  Firefox Developer Edition: 113.0
  Safari: 16.4
npmPackages:
  vite: ^4.3.3 => 4.3.3
  vite-plugin-web-extension: ^3.0.6 => 3.0.6
RC-14 commented 1 year ago

Personally I'd be OK with the "fix" for this being to just include "type": "module" in the package.json of the manual installation guide and mentioning it below in a warning box.

As it is right now the manual installation guide leaves you with an unusable project which is pretty annoying if you want to use it to migrate an existing code base.

aklinker1 commented 1 year ago

Thanks for the feedback! I've updated the docs: https://github.com/aklinker1/vite-plugin-web-extension/commit/29f74776bb1b32976291b4054e56dae81b8958e7

https://vite-plugin-web-extension.aklinker1.io/guide/#manual-project-setup

RC-14 commented 1 year ago

Nice. I'll close this issue then.