antfu-collective / vite-plugin-inspect

Inspect the intermediate state of Vite plugins
MIT License
1.25k stars 74 forks source link

error on `ESM` environment #13

Closed userquin closed 2 years ago

userquin commented 2 years ago

context: https://github.com/antfu/unplugin-auto-import/issues/79#issuecomment-977159278

failed to load config from C:\Users\joshua\test\vite.config.ts
Error: Dynamic require of "os" is not supported
    at __require (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:26:9)
    at node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:1156:14)
    at __require2 (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:29:44)
    at node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:1412:56)
    at __require2 (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:29:44)
    at file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:34444:31
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadConfigFromFile (C:\Users\joshua\test\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:68598:31)
userquin commented 2 years ago

@antfu it seems we are using chalk (not esm ready), changing to use kolorist (the same change we made on unplugin-icons)

EDIT: once removed chalk, now @rollup/pluginutils uses picomatch, not esm ready?, we can remove @rollup/pluginutils and include a custom implementation (just copy/paste from it): I'll try to clone the behavior, we also need to provide FilterPattern: https://github.com/rollup/plugins/issues/539

EDIT 2: to align with vite we should use micromatch: https://github.com/vitejs/vite/pull/5610

@josh-hemphill the error also using vitesse template repo?

josh-hemphill commented 2 years ago

josh-hemphill the error also using vitesse template repo?

I believe so, yes.

josh-hemphill commented 2 years ago

Yeah, that's the first error after changing the project type. Though to get vitesse working I have to do npm i -D critters@^0.0.10 @vueuse/head@^0.5.1 to get the packages to install.

RoenLie commented 2 years ago

Also having this issue when I set my package.json to type:module. Changing the export statement in vite plugin inspect to js instead of mjs solves the issue on my end. "exports": { ".": { "require": "./dist/index.js", "import": "./dist/index.js" // changed from mjs to js. } }

It does mean I have to import the plugin like this however. ( inspect as any ).default()

emme1444 commented 2 years ago

@userquin any updates on this?

userquin commented 2 years ago

@emme1444 I'm working on it right now

userquin commented 2 years ago

@emme1444 I have it working with vite + svelte and vitesse + type module + vitesse + NO type module (the same project): you can see it in action:

/cc @antfu PR in a few minutes: some plugins must be used with .default(), for example VueI18n and Layouts using vitesse project.