Search code examples
typescriptnpmpnpm

Typescript errors after switching from npm to pnpm


I am trying to switch a legacy (very old fashioned Angular JS) project from npm to pnpm and am struggling with typescript errors. The vast majority are things like error TS2339: Property 'mock' does not exist on type 'IAngularStatic'. Using npm I get a clean typescript transpile and I would like to keep it that way.

My tsconfig.json is

{
  "compilerOptions": {
    "baseUrl": ".",
    "module": "commonjs",
    "target": "ES2017",
    "sourceMap": true,
    "inlineSources": true,
    "allowSyntheticDefaultImports": true
  },
  "exclude": [
    "node_modules"
  ]
}

I have tried adding import "angular";import "angular-mocks"; and import "@types/angular";import "@types/angular-mocks"; but geterror TS2686: 'angular' refers to a UMD global, but the current file is a module. Consider adding an import instead.

I have also tried various hoisting options, but somewhat randomly as I don't have a great understanding of it.

Can someone point me in the right direction?

Edit: To clarify, if I do

rm -rf node_modules
rm package-lock.json pnpm-lock.yaml npm-shrinkwrap.json
npm i --ignore-scripts
tsc

I get no errors (but it takes ages) whereas

rm -rf node_modules
rm package-lock.json pnpm-lock.yaml npm-shrinkwrap.json
pnpm i --ignore-scripts
tsc

relatively quickly yields 170 or so tsc errors, the vast majority of which are TS2339 errors.


Solution

  • The problem here was resolved by using preserveSymLinks https://www.typescriptlang.org/tsconfig#preserveSymlinks