aklinker1 / vite-plugin-web-extension

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

Build fails when output folder does not exist #8

Closed ChrRubin closed 2 years ago

ChrRubin commented 2 years ago

Since 1.0.5, build will fail whenever the output folder does not exist. Here's the output when building the vanilla demo:

[vite-plugin-web-extension] Building for browser: chrome
[vite-plugin-web-extension] Building with vite config: {
  "root": "src",
  "build": {
    "outDir": "/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/dist",
    "emptyOutDir": false,
    "terserOptions": {
      "mangle": false
    },
    "rollupOptions": {
      "output": {
        "entryFileNames": "[name].js",
        "chunkFileNames": "[name].js",
        "assetFileNames": "[name].[ext]"
      },
      "input": "/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/src/index.html"
    }
  },
  "plugins": [
    {
      "name": "vite-plugin-web-extension"
    }
  ]
}
[vite-plugin-web-extension] Skipping script builds because of error Error: ENOENT: no such file or directory, stat '/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/dist'
    at Object.statSync (node:fs:1536:3)
    at __node_internal_ (node:internal/fs/utils:793:8)
    at rmdirSync (node:fs:1156:15)
    at Object.buildStart (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite-plugin-web-extension/dist/index.js:403:35)
    at /home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/rollup/dist/shared/rollup.js:22815:37
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 4)
    at rollupInternal (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/rollup/dist/shared/rollup.js:23557:9)
    at doBuild (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite/src/node/build.ts:585:20)
    at build (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite/src/node/build.ts:395:12) {
  errno: -2,
  syscall: 'stat',
  code: 'PLUGIN_ERROR',
  path: '/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/dist',
  pluginCode: 'ENOENT',
  plugin: 'vite-plugin-web-extension',
  hook: 'buildStart'
}
✓ 0 modules transformed.
[vite-plugin-web-extension] ENOENT: no such file or directory, stat '/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/dist'
error during build:
Error: ENOENT: no such file or directory, stat '/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/dist'
    at Object.statSync (node:fs:1536:3)
    at __node_internal_ (node:internal/fs/utils:793:8)
    at rmdirSync (node:fs:1156:15)
    at Object.buildStart (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite-plugin-web-extension/dist/index.js:403:35)
    at /home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/rollup/dist/shared/rollup.js:22815:37
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 4)
    at rollupInternal (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/rollup/dist/shared/rollup.js:23557:9)
    at doBuild (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite/src/node/build.ts:585:20)
    at build (/home/rubin/repos/vite-plugin-web-extension/demos/vanilla/node_modules/vite/src/node/build.ts:395:12)

This wasn't the case on 1.0.4. Not particularly detrimental, but it is slightly inconvenient since with emptyOutDir the output folder is removed if the build is cancelled partway.

aklinker1 commented 2 years ago

Interesting, if I delete the demos/vanilla/dist directory, and run pnpm build, it does not fail. Here's what I did:

git checkout main
git pull
cd demos/vanilla
rm -rf dist
pnpm build

What exact steps are you taking?

ChrRubin commented 2 years ago

I was using yarn to install dependencies and npx vite build to build, but I just tried pnpm build on a fresh git clone and it still fails.

aklinker1 commented 2 years ago

I don't have any contribution docs about setting up the repo... I'll add those. Could you share the exact commands from a fresh clone? I tried this and everything worked:

git clone git@github.com:aklinker1/vite-plugin-web-extension.git
cd vite-plugin-web-extension
pnpm i
cd demos/vanilla
pnpm vite build

I've also added some E2E tests that specifically test this, and they're all passing.

https://github.com/aklinker1/vite-plugin-web-extension/blob/63d244b0f2cdb0215560614ca1a51cddb7374ff9/tests/e2e.test.ts#L105-L142

What OS are you using? Maybe it's OS dependent?

aklinker1 commented 2 years ago

Published v1.0.7 with this PR