kintone/js-sdk

[Bug] dts-gen causes an error if TypeScript isn't installed

tasshi-me opened this issue · 1 comments

Summary

Related to kintone/js-sdk-ja#39.

The typescript dependency is missing on @kintone/dts-gen, so dts-gen causes an error during generating type definition file.

Target Package

@kintone/dts-gen

Target Version

v7.0.2

Reproduction

  1. Install @kintone/dts-gen
  2. Run dts-gen
yarn add -D @kintone/dts-gen
kintone-dts-gen --base-url $KINTONE_BASE_URL --api-token $KINTONE_API_TOKEN --app-id $APP_ID --type-name SampleFields --namespace company.name.types -o sample-fields.d.ts

Expected Behavior

User can execute dts-gen successfully without installing typescript manually.
(When installing dts-gen, typescript should be installed automatically)

Actual Behavior

The dts-gen causes an error.

Error: Failed to load plugin '@typescript-eslint' declared in 'BaseConfig » @cybozu/eslint-config/presets/typescript » ../lib/typescript.js': Cannot find module 'typescript'
Require stack:
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/util/astUtils.js
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/util/index.js
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/rules/adjacent-overload-signatures.js
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/index.js
- /Users/tasshi/Downloads/test-dts-gen/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Referenced from: /Users/tasshi/Downloads/test-dts-gen/node_modules/@cybozu/eslint-config/lib/typescript.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/util/astUtils.js:30:25)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/util/astUtils.js',
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/util/index.js',
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/rules/adjacent-overload-signatures.js',
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js',
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@typescript-eslint/eslint-plugin/dist/index.js',
    '/Users/tasshi/Downloads/test-dts-gen/node_modules/@eslint/eslintrc/dist/eslintrc.cjs'
  ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@cybozu/eslint-config includes typescript (and eslint) in peerDeps, so we need to add typescript to our deps manually.
https://github.com/cybozu/eslint-config/blob/master/package.json#L41

$ yarn add -D @kintone/dts-gen
yarn add v1.22.19
warning package.json: No license field
warning No license field
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "@kintone/dts-gen > @cybozu/eslint-config@18.0.3" has unmet peer dependency "typescript@^3.3.3333 || ^4.0.0 || ^5.0.0".
warning "@kintone/dts-gen > @cybozu/eslint-config > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".

WA: Install typescript manually

Environment

  System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 179.47 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nodenv/versions/16.17.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/.nodenv/versions/16.17.0/bin/npm
  npmPackages:
    @kintone/dts-gen: ^7.0.2 => 7.0.2

We decided not to do any implementation to fix it.

TypeScript is specified in peerDeps of @cybozu/eslint-config.
npm and pnpm install peerDeps automatically.
This issue only happens with Yarn.