質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

Q&A

解決済

1回答

1864閲覧

nestJSのnest newで生成したプロジェクトをnpm run startするとtypescriptのエラーが発生する

Kobay

総合スコア1

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

0グッド

0クリップ

投稿2021/01/23 07:53

編集2021/01/23 07:55

nest.jsとtypescriptを学習しようと思い、nestの公式サイトをみてfirst stepにあるプロジェクトの生成と実行をやろうとしていますが、typescript関連のエラーになってしまいます。

typescriptは初心者ですが、mochaとjestのtype定義の適用先でコンパイラが混乱しているような気がします。
どのようにすれば解決できるのでしょうか?

実行したステップは以下のとおりです。

sh

1npm i -g @nestjs/cli 2nest new nest-lesson # npmを選択 → プロジェクトが生成される 3cd nest-lesson 4npm run start # ここでエラー

表示されるエラーは以下のとおりです。

sh

1 2../../../node_modules/@types/mocha/index.d.ts:36:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'Describe', but here has type 'IContextDefinition'. 3 436 declare var describe: Mocha.IContextDefinition; 5 ~~~~~~~~ 6 7 node_modules/@types/jest/index.d.ts:38:13 8 38 declare var describe: jest.Describe; 9 ~~~~~~~~ 10 'describe' was also declared here. 11../../../node_modules/@types/mocha/index.d.ts:37:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'Describe', but here has type 'IContextDefinition'. 12 1337 declare var xdescribe: Mocha.IContextDefinition; 14 ~~~~~~~~~ 15 16 node_modules/@types/jest/index.d.ts:40:13 17 40 declare var xdescribe: jest.Describe; 18 ~~~~~~~~~ 19 'xdescribe' was also declared here. 20../../../node_modules/@types/mocha/index.d.ts:42:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'it' must be of type 'It', but here has type 'ITestDefinition'. 21 2242 declare var it: Mocha.ITestDefinition; 23 ~~ 24 25 node_modules/@types/jest/index.d.ts:41:13 26 41 declare var it: jest.It; 27 ~~ 28 'it' was also declared here. 29../../../node_modules/@types/mocha/index.d.ts:43:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'It', but here has type 'ITestDefinition'. 30 3143 declare var xit: Mocha.ITestDefinition; 32 ~~~ 33 34 node_modules/@types/jest/index.d.ts:43:13 35 43 declare var xit: jest.It; 36 ~~~ 37 'xit' was also declared here. 38../../../node_modules/@types/mocha/index.d.ts:45:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'test' must be of type 'It', but here has type 'ITestDefinition'. 39 4045 declare var test: Mocha.ITestDefinition; 41 ~~~~ 42 43 node_modules/@types/jest/index.d.ts:44:13 44 44 declare var test: jest.It; 45 ~~~~ 46 'test' was also declared here. 47../../../node_modules/@types/mocha/index.d.ts:63:18 - error TS2300: Duplicate identifier 'beforeEach'. 48 4963 declare function beforeEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 50 ~~~~~~~~~~ 51 52 node_modules/@types/jest/index.d.ts:35:13 53 35 declare var beforeEach: jest.Lifecycle; 54 ~~~~~~~~~~ 55 'beforeEach' was also declared here. 56../../../node_modules/@types/mocha/index.d.ts:64:18 - error TS2300: Duplicate identifier 'beforeEach'. 57 5864 declare function beforeEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 59 ~~~~~~~~~~ 60 61 node_modules/@types/jest/index.d.ts:35:13 62 35 declare var beforeEach: jest.Lifecycle; 63 ~~~~~~~~~~ 64 'beforeEach' was also declared here. 65../../../node_modules/@types/mocha/index.d.ts:65:18 - error TS2300: Duplicate identifier 'afterEach'. 66 6765 declare function afterEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 68 ~~~~~~~~~ 69 70 node_modules/@types/jest/index.d.ts:37:13 71 37 declare var afterEach: jest.Lifecycle; 72 ~~~~~~~~~ 73 'afterEach' was also declared here. 74../../../node_modules/@types/mocha/index.d.ts:66:18 - error TS2300: Duplicate identifier 'afterEach'. 75 7666 declare function afterEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 77 ~~~~~~~~~ 78 79 node_modules/@types/jest/index.d.ts:37:13 80 37 declare var afterEach: jest.Lifecycle; 81 ~~~~~~~~~ 82 'afterEach' was also declared here. 83node_modules/@types/jest/index.d.ts:35:13 - error TS2300: Duplicate identifier 'beforeEach'. 84 8535 declare var beforeEach: jest.Lifecycle; 86 ~~~~~~~~~~ 87 88 ../../../node_modules/@types/mocha/index.d.ts:63:18 89 63 declare function beforeEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 90 ~~~~~~~~~~ 91 'beforeEach' was also declared here. 92 ../../../node_modules/@types/mocha/index.d.ts:64:18 93 64 declare function beforeEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 94 ~~~~~~~~~~ 95 and here. 96node_modules/@types/jest/index.d.ts:37:13 - error TS2300: Duplicate identifier 'afterEach'. 97 9837 declare var afterEach: jest.Lifecycle; 99 ~~~~~~~~~ 100 101 ../../../node_modules/@types/mocha/index.d.ts:65:18 102 65 declare function afterEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 103 ~~~~~~~~~ 104 'afterEach' was also declared here. 105 ../../../node_modules/@types/mocha/index.d.ts:66:18 106 66 declare function afterEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void; 107 ~~~~~~~~~ 108 and here. 109 110Found 11 error(s). 111

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

親のディレクトリ(エラーメッセージから推測するとおそらく3つ上?)のnode_modulesに、@types/mochaが入っていませんか?
@types/mocha@types/jestはコンフリクトするようです。

tsconfig.jsonのcompilerOptions以下、"types"jestを追加することで解消されるかと思います。このオプションを使うことで、インクルードすべきグローバルな型定義を指定することができます。

"compilerOptions": { "types": ["jest"] }

typesオプションについて

投稿2021/01/23 10:51

uraway_

総合スコア116

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Kobay

2021/01/23 23:55

親フォルダに意図せずnode_modulesが入っていました。 削除したところ正常に起動できるようになりましたありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問