nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.69k stars 7.63k forks source link

peerDependencies are not included in package when sls deploy with Webpack. #8859

Closed ankit3blocks closed 2 years ago

ankit3blocks commented 2 years ago

Is there an existing issue for this?

Current behavior

Here is my dependencies,

serverless.yaml

service: backend-serverless provider: name: aws runtime: nodejs14.x region: ${env:REGION} stage: ${env:STAGE} profile: default deploymentBucket: name: ${self:service}-${env:STAGE} serverSideEncryption: AES256 environment: MONGO_URL: ${env:MONGO_URL} NODE_ENV: production apiGateway: shouldStartNameWithService: true

plugins:

package: exclude:

functions: index-function: handler: src/lambda.handler events:

custom: webpack: webpackConfig: webpack.config.js includeModules: true forceExclude:

const webpack = require("webpack"); const path = require("path"); const serverlessWebpack = require("serverless-webpack"); const nodeExternals = require("webpack-node-externals"); const Dotenv = require('dotenv-webpack');

module.exports = { entry: serverlessWebpack.lib.entries, target: 'node', mode: serverlessWebpack.lib.webpack.isLocal ? "development" : "production", node: { dirname: true }, devtool: 'source-map', externals: [nodeExternals()], module: { rules: [ { test: /.ts$/, use: [ { loader: "ts-loader" } ], include: [dirname], exclude: /node_modules/ } ] }, resolve: { extensions: [".ts", ".tsx", ".js"] }, output: { libraryTarget: "commonjs", path: path.join(__dirname, ".webpack"), filename: "[name].js" }, plugins: [ new Dotenv({ path: './.env', // Path to .env file (this is the default) safe: false, // load .env.example (defaults to "false" which does not use dotenv-safe) }) ] };

Minimum reproduction code

https://github.com/test

Steps to reproduce

apollo-server-core apollo-server-express are missing in node modules when deploying.

Serverless: Fetch dependency graph from /Users/apdetroja/test-nv-tom/mons-backend/package.json Serverless: Ignoring 2 NPM errors: Serverless: => peer dep missing: graphql@^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0, required by graphql-relay@0.6.0 Serverless: => peer dep missing: class-transformer@^0.2.0 || ^0.3.0 || ^0.4.0, required by @nestjs/mapped-types@1.0.0 Serverless: Adding explicit peers for dependency @nestjs/graphql Serverless: Skipping peers dependency @apollo/federation for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency @apollo/gateway for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency @apollo/subgraph for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency apollo-server-core for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency apollo-server-express for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency apollo-server-fastify for dependency @nestjs/graphql because it's optional Serverless: Skipping peers dependency ts-morph for dependency @nestjs/graphql because it's optional Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Skipping peers dependency cache-manager for dependency @nestjs/common because it's optional Serverless: Skipping peers dependency class-transformer for dependency @nestjs/common because it's optional Serverless: Skipping peers dependency class-validator for dependency @nestjs/common because it's optional Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Skipping peers dependency @nestjs/microservices for dependency @nestjs/core because it's optional Serverless: Skipping peers dependency @nestjs/platform-express for dependency @nestjs/core because it's optional Serverless: Skipping peers dependency @nestjs/websockets for dependency @nestjs/core because it's optional Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/mongoose Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency graphql-upload Serverless: Adding explicit peers for dependency graphql-relay Serverless: WARNING: Could not determine version of module aws-sdk Serverless: Adding explicit peers for dependency @nestjs/platform-express Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: WARNING: Could not determine version of module express Serverless: WARNING: Could not determine version of module mongodb Serverless: WARNING: Could not determine version of module bson Serverless: Package lock found - Using locked versions Serverless: Packing external modules: @nestjs/graphql@^9.1.2, @nestjs/common@^8.0.0, reflect-metadata@^0.1.13, rxjs@^7.2.0, @nestjs/core@^8.0.0, graphql@^15.4.0, @nestjs/mongoose@^9.0.1, mongoose@^6.0.13, graphql-upload@^13.0.0, class-validator@^0.13.2, graphql-relay@^0.6.0, lodash@^4.17.21, aws-sdk, @nestjs/platform-express@^8.0.0, @vendia/serverless-express@4.5.2, express, mongodb, base64-url@^2.3.3, bson, dotenv@^10.0.0, class-transformer@^0.5.1 Serverless: Package took [10856 ms] Serverless: Adding explicit peers for dependency @nestjs/graphql Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/mongoose Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency graphql-upload Serverless: Adding explicit peers for dependency graphql-relay Serverless: WARNING: Could not determine version of module aws-sdk Serverless: Adding explicit peers for dependency @nestjs/platform-express Serverless: Adding explicit peers for dependency @nestjs/common Serverless: Adding explicit peers for dependency @nestjs/core Serverless: Adding explicit peers for dependency @nestjs/common Serverless: WARNING: Could not determine version of module express Serverless: WARNING: Could not determine version of module mongodb Serverless: WARNING: Could not determine version of module bson Serverless: Copy modules: /Users/apdetroja/test-nv-tom/mons-backend/.webpack/service [1839 ms] Serverless: Prune: /Users/apdetroja/test-nv-tom/mons-backend/.webpack/service [1417 ms] Serverless: Run scripts: /Users/apdetroja/test-nv-tom/mons-backend/.webpack/service [1 ms] Serverless: Zip method used: native Serverless: Zip service: /Users/apdetroja/test-nv-tom/mons-backend/.webpack/service [3165 ms] Serverless: Copying existing artifacts... Serverless: Setting artifact for function 'index-function' to '.serverless/backend-serverless-aws-dynamodb.zip' Serverless: Packaging service... Serverless: Remove /Users/apdetroja/test-nv-tom/mons-backend/.webpack Serverless: Removing /Users/apdetroja/test-nv-tom/mons-backend/.webpack done Serverless: Using deployment bucket 'backend-serverless-aws-dynamodb-dev' Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts...

Expected behavior

It should adding in node_modules.

but I m getting the below error. { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'apollo-server-core'\nRequire stack:\n- /var/task/node_modules/@nestjs/graphql/dist/federation/graphql-federation.factory.js\n- /var/task/node_modules/@nestjs/graphql/dist/federation/index.js\n- /var/task/node_modules/@nestjs/graphql/dist/index.js\n- /var/task/node_modules/@nestjs/graphql/index.js\n- /var/task/src/lambda.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", "stack": [ "Runtime.ImportModuleError: Error: Cannot find module 'apollo-server-core'", "Require stack:", "- /var/task/node_modules/@nestjs/graphql/dist/federation/graphql-federation.factory.js", "- /var/task/node_modules/@nestjs/graphql/dist/federation/index.js", "- /var/task/node_modules/@nestjs/graphql/dist/index.js", "- /var/task/node_modules/@nestjs/graphql/index.js", "- /var/task/src/lambda.js", "- /var/runtime/UserFunction.js", "- /var/runtime/index.js", " at _loadUserApp (/var/runtime/UserFunction.js:202:13)", " at Object.module.exports.load (/var/runtime/UserFunction.js:242:17)", " at Object. (/var/runtime/index.js:43:30)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)", " at Module.load (internal/modules/cjs/loader.js:950:32)", " at Function.Module._load (internal/modules/cjs/loader.js:790:12)", " at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)", " at internal/main/run_main_module.js:17:47" ]

Package

Other package

No response

NestJS version

No response

Packages versions

"dependencies": { "@apollo/gateway": "^0.38.2", "apollo-server-core": "^3.0.0", "@nestjs/common": "^8.0.0", "@nestjs/config": "1.1.5", "@nestjs/core": "^8.0.0", "@nestjs/graphql": "^9.1.2", "@nestjs/mongoose": "^9.0.1", "@nestjs/platform-express": "^8.0.0", "@vendia/serverless-express": "4.5.2", "apollo-server-express": "^3.5.0", "aws-lambda": "^1.0.7", "aws-serverless-express": "^3.4.0", "base64-url": "^2.3.3", "class-transformer": "^0.5.1", "class-validator": "^0.13.2", "dotenv": "^10.0.0", "graphql": "^15.4.0", "graphql-relay": "^0.6.0", "graphql-tools": "^7.0.1", "graphql-upload": "^13.0.0", "lodash": "^4.17.21", "mongoose": "^6.0.13", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0", "ts-morph": "^13.0.2", "type-graphql": "1.1.1", "config": "^3.2.4" }, "peerDependencies": { "@apollo/gateway": "^0.29.0 || ^0.32.0 || ^0.33.0 || ^0.35.0 || ^0.38.0 || ^0.42.0", "@apollo/subgraph": "^0.1.2", "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "apollo-server-core": "^3.0.0", "apollo-server-express": "^3.1.2", "apollo-server-fastify": "^3.1.2", "eslint": "^6.0.0 || ^7.0.0", "graphql": "^15.5.1", "reflect-metadata": "^0.1.13", "ts-morph": "^11.0.3 || ^12.0.0 || ^13.0.0" }, "devDependencies": { "serverless-webpack": "^5.2.0", "@nestjs/cli": "^8.0.0", "@nestjs/schematics": "^8.0.0", "@nestjs/testing": "^8.2.3", "@shelf/jest-dynamodb": "2.1.0", "@types/aws-lambda": "8.10.85", "@types/config": "0.0.40", "@types/express": "^4.17.13", "@types/graphql-relay": "^0.4.11", "@types/graphql-upload": "^8.0.7", "@types/jest": "^27.0.1", "@types/js-yaml": "4.0.5", "@types/mongoose": "^5.10.5", "@types/node": "^16.0.0", "@types/serverless": "1.78.39", "@types/supertest": "^2.0.11", "@types/uuid": "^8.3.3", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", "change-case": "4.1.2", "copyfiles": "^2.4.1", "cpx": "^1.5.0", "cross-env": "7.0.3", "dotenv-webpack": "^7.0.3", "eslint": "^8.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "2.25.3", "eslint-plugin-prettier": "^4.0.0", "glob-promise": "4.2.2", "husky": ">=4", "jest": "^27.2.5", "js-yaml": "4.1.0", "lint-staged": ">=10", "mongodb-memory-server": "6.4.1", "prettier": "^2.3.2", "progress-bar-webpack-plugin": "^2.1.0", "serverless": "2.67.0", "serverless-deployment-bucket": "^1.5.1", "serverless-dotenv-plugin": "^3.10.0", "serverless-dynamodb-local": "0.2.40", "serverless-layers": "^2.0.3-aplha", "serverless-offline": "^6.1.4", "serverless-plugin-layer-manager": "^1.0.5", "serverless-plugin-optimize": "^4.1.4-rc.1", "serverless-plugin-typescript": "2.1.0", "source-map-support": "^0.5.20", "supertest": "^6.1.3", "ts-jest": "^27.0.3", "ts-loader": "^8.2.0", "ts-node": "^10.4.0", "tsconfig-paths": "^3.10.1", "tslint": "^6.1.3", "typescript": "^4.3.5", "webpack": "^4.43.0", "webpack-bundle-analyzer": "^3.8.0", "webpack-cli": "^3.3.12", "webpack-loader-helper": "^1.0.0", "webpack-node-externals": "^1.7.2" },

Node.js version

No response

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 2 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.