TomFern / semaphore-demo-monorepo-typescript

Yarn Workspaces + TypeScript monorepo
MIT License
17 stars 7 forks source link

error running build #1

Open rabiddroid opened 2 years ago

rabiddroid commented 2 years ago

I followed the instructions and getting error for step yarn tsc --build --force

Error seen:

packages/sayhi/tests/sayhi.test.ts:3:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha.

3 describe("check hello world message", () => {


packages/sayhi/tests/sayhi.test.ts:4:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

4   it("should return 'Hi, World!')", () => {
    ~~

packages/sayhi/tests/sayhi.test.ts:5:5 - error TS2304: Cannot find name 'expect'.

5     expect(getMessage()).toBe('Hi, World!');

packages/shared/tests/calc.test.ts:3:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha.

3 describe("test add function", () => {


packages/shared/tests/calc.test.ts:4:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

4   it("should return 20 for add(20,5)", () => {
    ~~

packages/shared/tests/calc.test.ts:5:5 - error TS2304: Cannot find name 'expect'.

5     expect(add(20, 5)).toBe(25);

packages/shared/tests/calc.test.ts:6:6 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha.

6 });it("should return 6 for add(1,5)", () => { ~~

packages/shared/tests/calc.test.ts:7:5 - error TS2304: Cannot find name 'expect'.

7 expect(add(1, 5)).toBe(6);

```
packages/shared/tests/hi.test.ts:3:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

3 describe("test hi function", () => {

packages/shared/tests/hi.test.ts:4:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha.

4 it("should return 'Hi, World!')", () => { ~~

packages/shared/tests/hi.test.ts:5:5 - error TS2304: Cannot find name 'expect'.

5 expect(hi()).toBe('Hi, World!');



Found 11 errors.
```
rabiddroid commented 2 years ago

I don't understand why... but if i add @types/jest to root e.g yarn add @types/jest --dev I no longer get the error.

SunnyAureliusRichard commented 2 years ago

I did that.

Next error I'm getting is

.yarn/cache/@jest-expect-utils-npm-29.0.2-cb84da96fb-12bb317b1d.zip/node_modules/@jest/expect-utils/build/index.d.ts:26:20 - error TS2583: Cannot find name 'WeakMap'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

26   seenReferences?: WeakMap<object, boolean>,
SunnyAureliusRichard commented 2 years ago

Fixed it by adding dependencies:

"@types/jest": "^27.0.1",
"@types/node": "^18.7.15",

and compilerOptions:

  "compilerOptions": {
    "types": ["node", "jest"],
  },
SunnyAureliusRichard commented 2 years ago

Also had to do this so it behaves in vs code: https://stackoverflow.com/a/69547593/1204843 https://yarnpkg.com/getting-started/editor-sdks

rabiddroid commented 2 years ago

Fixed it by adding dependencies:

"@types/jest": "^27.0.1",
"@types/node": "^18.7.15",

and compilerOptions:

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

Interesting you had to explicitly add the compiler options. According to documentation, @types installed will automatically be included unless you start to specify in the compiler options. once specified it will only respect what is listed. ref: https://www.typescriptlang.org/tsconfig#types