TypeScript-Node-Starter
TypeScript-Node-Starter copied to clipboard
Using yarn (instead of npm) leads to typescript compilation errors
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'.
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
I'm here for the same reason.
Is this still an issue?
@peterblazejewicz Yes, It is still an issue for me #117
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!? :)
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
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/*"
]
}
}
}
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
Great. Then please add a note on that in the usage/install docs and close this issue.
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