Skip to content

Nest 9.1.3 version does not work with webpack config from the serverless page #10367

@alejandrombc

Description

@alejandrombc

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

If you follow the tutorial about serverless + nest (https://docs.nestjs.com/faq/serverless) you will get a webpack.config.js file that works perfectly with 9.1.2 version but not on the 9.1.3.

When you do a fresh install and then run nest build --webpack you will get the following error:

Module not found: Error: Can't resolve 'cache-manager/package.json' in '/nest-project/node_modules/@nestjs/common/cache'

webpack file:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = (options, webpack) => {
  const lazyImports = [
    '@nestjs/microservices/microservices-module',
    '@nestjs/websockets/socket-module',
  ];

  return {
    ...options,
    externals: [],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            keep_classnames: true,
          },
        }),
      ],
    },
    output: {
      ...options.output,
      libraryTarget: 'commonjs2',
    },
    plugins: [
      ...options.plugins,
      new webpack.IgnorePlugin({
        checkResource(resource) {
          if (lazyImports.includes(resource)) {
            try {
              require.resolve(resource);
            } catch (err) {
              return true;
            }
          }
          return false;
        },
      }),
    ],
  };
};

Minimum reproduction code

May be not necessary

Steps to reproduce

No response

Expected behavior

To compile the code like 9.1.2 did

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9.1.3

Packages versions

  "dependencies": {
    "@nestjs/common": "9.1.3",
    "@nestjs/core": "9.1.3",
    "@nestjs/platform-express": "9.1.3",
    "@vendia/serverless-express": "^4.10.1",
    "aws-lambda": "^1.0.7",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "9.1.4",
    "@nestjs/schematics": "9.0.3",
    "@nestjs/testing": "9.1.3",
    "@types/aws-lambda": "^8.10.106",
    "@types/express": "^4.17.13",
    "@types/jest": "28.1.8",
    "@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.1.3",
    "prettier": "^2.3.2",
    "serverless": "^3.22.0",
    "serverless-jetpack": "^0.11.1",
    "serverless-offline": "^9.0.0",
    "serverless-plugin-warmup": "^8.1.0",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "terser-webpack-plugin": "^5.3.6",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.7.4"
  },

Node.js version

16.12.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions