actions / toolkit

The GitHub ToolKit for developing GitHub Actions.
https://github.com/features/actions
MIT License
4.8k stars 1.37k forks source link

TS2307: Cannot find module or its corresponding type declarations #1067

Open Lauriero opened 2 years ago

Lauriero commented 2 years ago

Hi there. I'm currently developing custom github action with typescript and I want to use npm package inside of action project. But unfortunately, I get "TS2307: Cannot find module 'typescript-json-serializer' or its corresponding type declarations" error when running github action runner runs tsc -p tsconfig.json. I tested this build on my PC with Windows 10 OS and in Ubuntu 20.04 server and it works fine.

My .github/workflows/generator.yml

name: Generator
on:
  push:
    branches:
      - develop
    paths:
      - 'src/**/*.ts'
      - 'github-actions/**/*.*'
      - '.github/workflows/**/*.*'

  pull_request:
    branches:
      - develop

jobs:
  generator:
    name: Libraries generating action
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Use NodeJS 16.X
        uses: actions/setup-node@v2
        with:
          node-version: 16.x
          cache: 'npm'
          cache-dependency-path: package-lock.json

      - name: Switch npm package repository
        run: cd github_actions && npm config set registry https://registry.npmjs.org/

      - name: Install dependencies
        run: cd github_actions && npm i

      - name: Install serializer
        run: cd github_actions && npm i --save typescript-json-serializer

      - name: Test
        run: cd github_actions && cat package.json && cat package-lock.json

      - name: Build
        run: cd github_actions && npm run build

      - name: Run generator action
        uses: ./github_actions/
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
          COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
          COMMIT_AUTHOR: ${{ github.event.head_commit.author }}

      - uses: EndBug/add-and-commit@v9
        with:
          message: "style: generate new scheme and raise package version"
          committer_name: Lauriero
          committer_email: incorobots@gmail.com

My package.json

{
  "name": "github-actions",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "scripts": {
    "build": "tsc -p tsconfig.json"
  },
  "author": "Lauriero",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^17.0.30",
    "typescript": "^4.6.4"
  },
  "dependencies": {
    "@actions/core": "^1.7.0",
    "@actions/github": "^5.0.1",
    "discord-webhook-ts": "^5.0.0",
    "reflect-metadata": "^0.1.13",
    "typed-github-api": "^1.2.6",
    "typescript-json-serializer": "^4.1.1"
  }
}

My tsconfig.json

{
    "compilerOptions": {
        "types": [
            "node",
            "reflect-metadata",
            "typescript-json-serializer"
        ],
        "allowJs": true,
        "target": "ESNext",
        "outDir": "dist",
        "module": "commonjs",
        "lib": ["ESNext"],
        "strict": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
    },
    "include": ["src/**/*.ts"],
    "exclude": ["src/**/*.spec.ts"]
}

Also package.json and package-lock.json in runner environment have typescript-json-serializer installed. As you can see, I make runner install this package manually but it doesn't help. Any help would be appreciated.

Lauriero commented 2 years ago

I closed it because I didn't see that the error contains files that are not in the source folder: Error: ../src/model/client/commands/Command.ts(1,42): error TS2307: Cannot find module 'typescript-json-serializer' or its corresponding type declarations. These files are not even used in this project. There's no reason for them to be compiled with tsc. But as I already said, this is not happening on other platform I tested, even in Ubuntu 20.04