app-config icon indicating copy to clipboard operation
app-config copied to clipboard

vite plugin / vite example project do not work

Open afreidz opened this issue 2 years ago • 10 comments

When i install/use the vite plugin on a project I am unable to run the app. I also tried a fresh copy of the vite example in this repo and was met with the same error:

Error: Build failed with 25 errors:
node_modules/@app-config/config/dist/es/index.js:1:9: ERROR: No matching export in "browser-external:path" for import "join"
node_modules/@app-config/core/dist/es/config-source.js:1:9: ERROR: No matching export in "browser-external:path" for import "extname"
node_modules/@app-config/core/dist/es/config-source.js:4:9: ERROR: No matching export in "node_modules/json5/dist/index.mjs" for import "parse"
node_modules/@app-config/core/dist/es/config-source.js:4:30: ERROR: No matching export in "node_modules/json5/dist/index.mjs" for import "stringify"
node_modules/@app-config/core/dist/es/parsed-value.js:1:9: ERROR: No matching export in "browser-external:util" for import "inspect"
...
    at failureErrorWithLog (/Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:1624:15)
    at /Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:1266:28
    at runOnEndCallbacks (/Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:1046:63)
    at buildResponseToResult (/Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:1264:7)
    at /Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:1377:14
    at /Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:678:9
    at handleIncomingPacket (/Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:775:9)
    at Socket.readFromStdout (/Users/afreide/Code/vite-project/node_modules/esbuild/lib/main.js:644:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)

nodejs version: v16.18.1

Repo steps:

  • clone/download monorepo
  • run npm i from /examples/vite-project
  • run npm start
  • build fails

afreidz avatar Nov 07 '22 21:11 afreidz

We use yarn for the monorepo, I imagine the issue is npm works differently? We do check that the vite plugin works in CI

joelgallant avatar Nov 08 '22 16:11 joelgallant

I can try yarn ... but doesn't it stand to reason that many people would be using npm when depending on the vite plugin? if you are able to get it to work with npm then im good with considering this user/env-error 😄

afreidz avatar Nov 08 '22 17:11 afreidz

In general all npm packages are consumable by any package manager. But within our repo, we have the monorepo setup using yarn.

So for your own repos, you can definitely consume app-config using npm.

On Tue, Nov 8, 2022, at 10:05 AM, Andy Freidenfelds wrote:

I can try yarn ... but doesn't it stand to reason that many people would be using npm when depending on the vite plugin? if you are able to get it to work with npm then im good with considering this user/env-error 😄

— Reply to this email directly, view it on GitHub https://github.com/launchcodedev/app-config/issues/211#issuecomment-1307541160, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK5D2RMIIVICNZLJZBLIRDWHKB4TANCNFSM6AAAAAARZUECMQ. You are receiving this because you commented.Message ID: @.***>

joelgallant avatar Nov 08 '22 17:11 joelgallant

ok ... thats what i tried, and when consuming the vite plugin, vite will not build and produces module export errors in json5 like the above stack. perhaps a recent release of json5 is breaking something here? can you confirm that the vite plugin is working within the last day or 2?

afreidz avatar Nov 08 '22 17:11 afreidz

UPDATE: i can get both the example project and my repo to work if i build vite and serve the output from /dist ... however vite will not build/run in development mode (same error as above) with neither npm nor yarn

afreidz avatar Nov 08 '22 17:11 afreidz

I can give it a look over the weekend for sure. I havent paid close attention to vite release since first writing the plugin, so an issue with hot reloading or dev mode setup in general is possible (usually that's a separate flow in bundlers).

On Tue, Nov 8, 2022, at 10:55 AM, Andy Freidenfelds wrote:

UPDATE: i can get both the example project and my repo to work if i build vite and serve the output from /dist ... however vite will not build/run in development mode (same error as above) with neither npm nor yarn

— Reply to this email directly, view it on GitHub https://github.com/launchcodedev/app-config/issues/211#issuecomment-1307613267, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK5D2Q7JGKYDI5HJ5D3NULWHKHZBANCNFSM6AAAAAARZUECMQ. You are receiving this because you commented.Message ID: @.***>

joelgallant avatar Nov 08 '22 18:11 joelgallant

thanks! strange. for now i was able to work around it by running a build step to output app-config to .env ... which vite supports ootb

afreidz avatar Nov 08 '22 19:11 afreidz

Just for the record, I was able to repro this as described in a clean vite project. Will try and get a fix out today if I can find the issue.

joelgallant avatar Nov 13 '22 18:11 joelgallant

Yeah, this is somewhat trickier than I thought. The plugin system doesn't work consistently between dev and prod builds, and plugin API has changes a bit from v2 and v3. I would need more than the couple hours I have today to get this all sorted out.

fwiw, I think it's basically caused by the "virtual module" concept, which breaks module names - the plugin uses names of modules (appConigImportRegex) to determine if it should intercept loading.

Thanks for pointing this out! This is definitely the tricky bit when authoring a plugin for a build system I don't currently dogfood - API docs and stability tend to be fast moving and need consumers to point out breakages.

joelgallant avatar Nov 14 '22 00:11 joelgallant

no worries at all! thanks for looking into it. and yea things always move at a pace faster than most can keep up! i just took a look at the sveltekit docs for the first time in 6 months 🤣

On Sun, Nov 13, 2022, 6:00 PM Joel Gallant @.***> wrote:

Yeah, this is somewhat trickier than I thought. The plugin system doesn't work consistently between dev and prod builds, and plugin API has changes a bit from v2 and v3. I would need more than the couple hours I have today to get this all sorted out.

fwiw, I think it's basically caused by the "virtual module" concept, which breaks module names - the plugin uses names of modules ( appConigImportRegex) to determine if it should intercept loading.

Thanks for pointing this out! This is definitely the tricky bit when authoring a plugin for a build system I don't currently dogfood - API docs and stability tend to be fast moving and need consumers to point out breakages.

— Reply to this email directly, view it on GitHub https://github.com/launchcodedev/app-config/issues/211#issuecomment-1312858292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI2YZ5ZUULFT4MCWQXZ3XTWIF6JBANCNFSM6AAAAAARZUECMQ . You are receiving this because you authored the thread.Message ID: @.***>

afreidz avatar Nov 14 '22 00:11 afreidz