niku98 / vite-env-caster

A Vite's plugin to cast environment variables to javascript type
MIT License
5 stars 2 forks source link

Adding this plugin will fail compiling with "EnvCaster is not a function" #1

Open Moongazer opened 11 months ago

Moongazer commented 11 months ago

I've installed and added this plugin like mentioned in the docs, but starting the compiling throws an exception (see below).

vite.config.ts:

import EnvCaster from '@niku/vite-env-caster'

export default defineConfig({
  envPrefix: 'XYZ_',
  plugins: [
    EnvCaster(), // calling without options should be fine, right?
    vue({/*...*/})
  ]
})

Error running npm run dev:

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
failed to load config from /speeddrive/webserver/vendor/frontends/my-project/vite.config.ts
error when starting dev server:
TypeError: EnvCaster is not a function
    at file:///speeddrive/webserver/vendor/frontends/my-project/vite.config.ts.timestamp-1703252334437-371455b7ec957.mjs:11:5
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadConfigFromBundledFile (file:///speeddrive/webserver/vendor/frontends/my-project/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:68017:21)
    at async loadConfigFromFile (file:///speeddrive/webserver/vendor/frontends/my-project/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67874:28)
    at async resolveConfig (file:///speeddrive/webserver/vendor/frontends/my-project/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67475:28)
    at async _createServer (file:///speeddrive/webserver/vendor/frontends/my-project/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:59972:20)
    at async CAC.<anonymous> (file:///speeddrive/webserver/vendor/frontends/my-project/node_modules/vite/dist/node/cli.js:764:24)

Environment (from package.json):

"@niku/vite-env-caster": "^1.0.1",
"vue": "^3.3.11",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.19.3",
"@vitejs/plugin-vue": "^4.5.2",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/tsconfig": "^0.5.0",
"typescript": "~5.3.0",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"

npm v9.9.2 node v16.13.0

What can be the issue here?

niku98 commented 1 month ago

@Moongazer Can you provide a re-production?