TypeScript-Node-Starter icon indicating copy to clipboard operation
TypeScript-Node-Starter copied to clipboard

Using yarn (instead of npm) leads to typescript compilation errors

Open jfburdet opened this issue 6 years ago • 10 comments

See https://asciinema.org/a/IARDsufZ2CEYvfuvDAUogExGz

Doing yarn install && yarn start leads to compile error.

Doing npm install && npm run lead to fine running node application.

> tsc

node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(36,7): error TS2300: Duplicate identifier 'serialize'.
node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(41,7): error TS2300: Duplicate identifier 'regenerate'.
node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(42,7): error TS2300: Duplicate identifier 'destroy'.
node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(43,7): error TS2300: Duplicate identifier 'reload'.
node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(44,7): error TS2300: Duplicate identifier 'save'.
node_modules/@types/connect-mongo/node_modules/@types/express-session/index.d.ts(45,7): error TS2300: Duplicate identifier 'touch'.
node_modules/@types/express-session/index.d.ts(21,5): error TS2300: Duplicate identifier 'regenerate'.
node_modules/@types/express-session/index.d.ts(22,5): error TS2300: Duplicate identifier 'destroy'.
node_modules/@types/express-session/index.d.ts(23,5): error TS2300: Duplicate identifier 'reload'.
node_modules/@types/express-session/index.d.ts(24,5): error TS2300: Duplicate identifier 'save'.
node_modules/@types/express-session/index.d.ts(25,5): error TS2300: Duplicate identifier 'touch'.
node_modules/@types/express-session/index.d.ts(37,5): error TS2300: Duplicate identifier 'serialize'.

jfburdet avatar Nov 03 '17 23:11 jfburdet

I removed @types/express-session from devDependencies, then ran yarn install. It worked.

Yarn does a pretty good job of flattening dependencies. Since @types/express-session is a dependency of @types/connect-mongo, it's not needed at the top level.

This fix works in this branch of my fork: https://github.com/UIUXEngineering/TypeScript-Node-Starter/tree/yarn-update-dep if you want test it.

I'm not going to submit a PR since owners don't want to use yarn: https://github.com/Microsoft/TypeScript-Node-Starter/pull/33

jerryorta-dev avatar Nov 11 '17 10:11 jerryorta-dev

I'm here for the same reason.

kahurangitama avatar Nov 28 '17 15:11 kahurangitama

Is this still an issue?

carbon

peterblazejewicz avatar Dec 16 '17 22:12 peterblazejewicz

@peterblazejewicz Yes, It is still an issue for me #117

muditsaurabh avatar May 30 '18 10:05 muditsaurabh

I'm getting thousands of lint errors (incl. all dependencies) running npm run build Installed dependencies using yarn as I otherwise got an error trying to use npm install

➜  TypeScript-Node-Starter git:(master) npm install
/usr/local/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_writable.js:480
      asyncWrite(afterWrite, stream, state, finished, cb);
      ^

TypeError: asyncWrite is not a function
    at onwrite (/usr/local/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_writable.js:480:7)
    at WritableState.onwrite (/usr/local/lib/n
➜  TypeScript-Node-Starter git:(master) npm run build
... 1000s of linting errors!!
node_modules/@types/mongoose/index.d.ts:2840:5 - error TS2374: Duplicate string index signature.

Any suggestions!? :)

kristianmandrup avatar Jul 06 '18 11:07 kristianmandrup

Looks like the asyncWrite error is quite a common issue

"You have to downgrade the node version to latest stable version i.e 8.11.2 because latest version of node is not compatible yet with all npm modules."

https://stackoverflow.com/questions/50597159/npm-err-asyncwrite-is-not-a-function

"I am guessing it is an incompatibility between npm v5 and node v10. To solve this I downgraded node to v9, upgraded npm to v6, then upgraded node to v10:"

sudo n 9.10.1
npm i -g npm
sudo n stable

Alternatively

sudo npm cache clean -f
sudo n 8.11.2

kristianmandrup avatar Jul 06 '18 11:07 kristianmandrup

If you want using yarn instead of npm, you can ignore errors by adding below options to tsconfig.json:

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,

Result of tsconfig.json:

    {
        "compilerOptions": {
            "module": "commonjs",
            "esModuleInterop": true,
            "target": "es6",
            "noImplicitAny": true,
            "moduleResolution": "node",
            "sourceMap": false,
            "outDir": "dist",
            "baseUrl": ".",
            "experimentalDecorators": true,
            "emitDecoratorMetadata": true,
            "skipLibCheck": true,
            "paths": {
                "*": [
                    "node_modules/*",
                    "src/types/*"
                ]
            }
        }
    }

mehdi-yeganeh avatar Apr 29 '19 19:04 mehdi-yeganeh

I fixed this issue by running yarn import this will create yarn.lock for you based on project's package-lock.json (more info) and then after having my yarn.lock I deleted package-lock.json

omnajjar avatar May 15 '19 00:05 omnajjar

Great. Then please add a note on that in the usage/install docs and close this issue.

kristianmandrup avatar May 15 '19 06:05 kristianmandrup

Old issue but still actual for me.

I solved by running

yarn add --dev typescript@~4.3.2

since 4.4.x trigger this issue

Eomm avatar Sep 06 '21 09:09 Eomm