axe-me / vite-plugin-node

Vite plugin to run your node dev server with HMR!
1k stars 48 forks source link

[ERROR] Error That Doesn't Affect Compilation #45

Closed angelhdzdev closed 2 years ago

angelhdzdev commented 2 years ago

After running npm run dev which runs vite, I'm receiving an error that doesn't affect compilation, but I would like to get rid of it.

image

After the error, everything runs perfectly:

image

package.json:

"dependencies": {
    "@nestjs/common": "^8.0.0",
    "@nestjs/core": "^8.0.0",
    "@nestjs/platform-express": "^8.0.0",
    "@prisma/client": "^3.13.0",
    "@swc/core": "^1.2.181",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^8.0.0",
    "@nestjs/schematics": "^8.0.0",
    "@nestjs/testing": "^8.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "27.5.0",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "28.0.3",
    "prettier": "^2.3.2",
    "prisma": "^3.13.0",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "28.0.1",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.0.0",
    "typescript": "^4.3.5",
    "vite": "^2.9.8",
    "vite-plugin-node": "0.0.19"
  }

tsconfig.json:

{
  "compilerOptions": {
    "module": "ESNext",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ESNext",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "moduleResolution": "node",

  }
}

vite.config.ts:

import { defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';

export default defineConfig({
  server: {
    open: true
  },
  plugins: [
    ...VitePluginNode({
      adapter: 'nest',
      appPath: './src/main.ts',
      tsCompiler: 'swc',
    }),
  ],
});

Thanks.

angelhdzdev commented 2 years ago

Update

Before the error with the red text, I get the following error:

  vite v2.9.8 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 295ms.

X [ERROR] Could not resolve "cache-manager"

    node_modules/@nestjs/common/cache/cache.providers.js:16:116:
      16 │ ...() => require('cache-manager'));
         ╵                  ~~~~~~~~~~~~~~~

  You can mark the path "cache-manager" as
  external to exclude it from the bundle,      
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

X [ERROR] Could not resolve "class-validator"

    node_modules/@nestjs/common/pipes/validation.pipe.js:31:182:
      31 │ ...=> require('class-validator'))); 
         ╵               ~~~~~~~~~~~~~~~~~     

  You can mark the path "class-validator" as   
  external to exclude it from the bundle,      
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

X [ERROR] Could not resolve "@nestjs/microservices"

    node_modules/@nestjs/core/nest-factory.js:52:128:
      52 │ ...quire('@nestjs/microservices')); 
         ╵          ~~~~~~~~~~~~~~~~~~~~~~~    

  You can mark the path
  "@nestjs/microservices" as external to       
  exclude it from the bundle, which will       
  remove this error. You can also surround     
  this "require" call with a try/catch block   
  to handle this failure at run-time instead   
  of bundle-time.

X [ERROR] Could not resolve "class-transformer"

    node_modules/@nestjs/common/serializer/class-serializer.interceptor.js:22:252:
      22 │ ...> require('class-transformer')); 
         ╵              ~~~~~~~~~~~~~~~~~~~    

  You can mark the path "class-transformer" as 
  external to exclude it from the bundle,      
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

X [ERROR] Could not resolve "class-transformer"

    node_modules/@nestjs/common/pipes/validation.pipe.js:34:190:
      34 │ ... require('class-transformer'))); 
         ╵             ~~~~~~~~~~~~~~~~~~~     

  You can mark the path "class-transformer" as 
  external to exclude it from the bundle,      
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

X [ERROR] Could not resolve "@nestjs/websockets/socket-module"

    node_modules/@nestjs/core/nest-application.js:18:115:
      18 │ ...ire('@nestjs/websockets/socke... 
         ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~    

  You can mark the path
  "@nestjs/websockets/socket-module" as        
  external to exclude it from the bundle,      
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

X [ERROR] Could not resolve "@nestjs/microservices/microservices-module"

    node_modules/@nestjs/core/nest-application.js:19:132:
      19 │ ...ire('@nestjs/microservices/mi... 
         ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~    

  You can mark the path
  "@nestjs/microservices/microservices-module" 
  as external to exclude it from the bundle,   
  which will remove this error. You can also   
  surround this "require" call with a
  try/catch block to handle this failure at    
  run-time instead of bundle-time.

reflect-metadata doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
X [ERROR] Could not resolve "@nestjs/microservices"

    node_modules/@nestjs/core/nest-application.js:117:128:
      117 │ ...uire('@nestjs/microservices')); 
          ╵         ~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path
  "@nestjs/microservices" as external to       
  exclude it from the bundle, which will       
  remove this error. You can also surround     
  this "require" call with a try/catch block   
  to handle this failure at run-time instead   
  of bundle-time.
angelhdzdev commented 2 years ago

Solved

https://github.com/axe-me/vite-plugin-node/issues/38