#ERROR [PackageLoader] The "@nestjs/platform-express"

1 messages · Page 1 of 1 (latest)

torpid lake
#

Hi, I got an error in the end-to-end testing process.
Locally it works fine. However, when I run through GitHub actions, it displays this error:

[Nest] 2787  - 01/20/2023, 5:20:08 PM   ERROR [PackageLoader] The "@nestjs/platform-express" package is missing. Please, make sure to install this library ($ npm install @nestjs/platform-express) to take advantage of NestFactory.
  ●  process.exit called with "1"

      13 |     }).compile();
      14 |
    > 15 |     app = moduleRef.createNestApplication();
         |                     ^
      16 |
      17 |     const validationPipe = new ValidationPipe({
      18 |       transform: true,

      at loadPackage (../../node_modules/@nestjs/common/utils/load-package.util.js:14:17)
      at TestingModule.createHttpAdapter (../../node_modules/@nestjs/testing/testing-module.js:31:72)
      at TestingModule.createNestApplication (../../node_modules/@nestjs/testing/testing-module.js:19:21)
      at Object.<anonymous> (test/app.e2e.spec.ts:15:21)

E2E spec:

  let app: INestApplication;

  beforeAll(async () => {
    const moduleRef = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = moduleRef.createNestApplication();

    const validationPipe = new ValidationPipe({
      transform: true,
    });

    app.useGlobalPipes(validationPipe);

    await app.init();
  });

Has anyone experienced this failure?

Thanks in advance for the help.

crisp sluice
#

can you show your workflow yaml file?
I've been using GHA just fine

torpid lake
#
test:
  runs-on: ubuntu-latest
  name: Test for Cats
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  steps:
    - name: Checkout
      uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: "16"
        cache: "yarn"
        cache-dependency-path: "./packages/yarn.lock"

    - name: Install dependencies
      run: yarn --cwd "./packages" install

    - name: Jest e2e
      working-directory: ./packages/cats
      run: yarn test:e2e

package.json

"scripts": {
  "db:migrate:test": ". ./.env.test && DATABASE_URL=$DATABASE_URL yarn prisma migrate dev",
  "db:seed:test": ". ./.env.test && DATABASE_URL=$DATABASE_URL yarn prisma db seed",
  "docker:up": "docker-compose -f ../../docker-compose.test.yml up -d",
  "docker:down": "docker-compose -f ../../docker-compose.test.yml down",
  "test:e2e:run": "DOTENV_CONFIG_PATH=.env.test jest --config=jest-e2e.json --setupFiles=dotenv/config",
  "test:e2e": "yarn docker:up && yarn db:migrate:test && yarn db:seed:test && yarn test:e2e:run && yarn docker:down"
},
#

If I use FastifyAdapter and NestFastifyApplication instead, it works fine.

beforeAll(async () => {
  const moduleRef = await Test.createTestingModule({
    imports: [AppModule],
  }).compile();

  app = moduleRef.createNestApplication<NestFastifyApplication>(
    new FastifyAdapter(),
  );

  const validationPipe = new ValidationPipe({
    transform: true,
  });

  app.useGlobalPipes(validationPipe);

  await app.init();
  await app.getHttpAdapter().getInstance().ready();
});
crisp sluice
#

first of all, choose one adapter

#

it would be express or fastify?

crisp sluice
torpid lake
crisp sluice
#

can you run npm ls express

#

I mean, yarn why express

torpid lake
# crisp sluice can you show all your dependencies at `package.json`
  "dependencies": {
    "@nestjs/common": "^9.2.1",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.2.1",
    "@nestjs/platform-express": "^9.2.1",
    "aws-sdk": "^2.1292.0",
    "aws-serverless-express": "^3.4.0",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.1.8",
    "@nestjs/platform-fastify": "^9.2.1",
    "@nestjs/schematics": "^9.0.4",
    "@nestjs/testing": "^9.2.1",
    "@types/aws-serverless-express": "^3.3.5",
    "@types/jest": "29.2.4",
    "@types/node": "18.11.18",
    "@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": "29.3.1",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "29.0.3",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.1",
    "typescript": "^4.7.4"
  },
crisp sluice
#

looks fine

#

have you tried yarn --cwd "./packages" install locally?

torpid lake
crisp sluice
#

add one step to run yarn why express in your workflow along with working-directory: ./packages/cats

torpid lake
#

ok i will try that

#

same error

crisp sluice
#

that's not for solving the error, it's for debugging

#

which output did you got

#

mine looks like this