axe-me / vite-plugin-node

Vite plugin to run your node dev server with HMR!
986 stars 46 forks source link

NestJS example not working #88

Open ghost opened 1 year ago

ghost commented 1 year ago

Hello. Currently it's not possible to run the NestJS example with the current TS configuration. If trying to run pnpm start yields:

> nest start

DeprecationWarning: 'getMutableClone' has been deprecated since v4.0.0. Use an appropriate `factory.update...` method instead, use `setCommentRange` or `setSourceMapRange`, and avoid setting `parent`.
src/main.ts:4:5 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

4 if (import.meta.env.PROD) {
      ~~~~~~~~~~~
src/main.ts:4:17 - error TS2339: Property 'env' does not exist on type 'ImportMeta'.

4 if (import.meta.env.PROD) {
                  ~~~

Found 2 error(s).

And then, changing module to "es2020" and adding 'moduleResolution: "node"' in tsconfig.json:

DeprecationWarning: 'getMutableClone' has been deprecated since v4.0.0. Use an appropriate `factory.update...` method instead, use `setCommentRange` or `setSourceMapRange`, and avoid setting `parent`.
src/main.ts:4:17 - error TS2339: Property 'env' does not exist on type 'ImportMeta'.

4 if (import.meta.env.PROD) {
                  ~~~

Is it outdated or did I forget some configuration?

WinmezzZ commented 1 year ago

Try add this two options into tsconfig.json

{
   "compilerOptions": {
    // ...
     "module": "ESNext",
     "moduleResolution": "node",
    // ...
   }
}
ghost commented 1 year ago

I tried it and had the same output, only this time, I tried to execute from within the "examples" folder of this repository, so another error was added into the fold:

> nest@0.0.1 start /home/stanley/ent/vite-plugin-node/examples/nest
> nest start

src/main.ts:4:17 - error TS2339: Property 'env' does not exist on type 'ImportMeta'.

4 if (import.meta.env.PROD) {
                  ~~~
vite.config.ts:2:32 - error TS2307: Cannot find module 'vite-plugin-node' or its corresponding type declarations.

2 import { VitePluginNode } from 'vite-plugin-node';
                                 ~~~~~~~~~~~~~~~~~~

Found 2 error(s).

 ELIFECYCLE  Command failed with exit code 1.

Some remarks:

ghost commented 1 year ago

My guess is that I need to create a type definition for ImportMetaEnv manually: https://vitejs.dev/guide/env-and-mode.html#intellisense-for-typescript

I'll try this later.