jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.28k stars 507 forks source link

Typings problems in rush monorepo (pnpm hard links) #953

Open Sinled opened 3 years ago

Sinled commented 3 years ago

Current Behavior

tsdx build fails inside rush monorepo, when importing third party types and modules

(typescript) Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.
Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.
    at error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at throwPluginError (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:11878:12)
    at Object.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:12912:24)
    at Object.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:12081:38)
    at RollupContext.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:17237:30)
    at /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25033:23
    at arrayEach (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:545:11)
    at Function.forEach (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:9397:14)
    at printDiagnostics (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25006:12)
    at Object.transform (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:29277:17)

Expected behavior

build success

Suggested solution(s)

i don't know

Additional context

here is reproduction repo https://github.com/Sinled/test-rushx-tsdx (but it needs rush)

git clone https://github.com/Sinled/test-rushx-tsdx
rush update
rush build

i am not sure if this is tsdx or rush problem, on the one hand, if i use tsc - instead of tsdx - it builds fine

cd packages/somelib
./node_modules/.bin/tsc --noEmit false 

but on the other - if i install dependencies directly inside package - tsdx also builds ok

Your environment

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 459.79 MB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.15.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 87.0.4280.141
    Firefox: 81.0.1
    Safari: 14.0.1

Any ideas how this can be solved?

agilgur5 commented 3 years ago
(typescript) Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.
Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.

So OUFR has had errors before: #461

I'm not really sure how rush works but if it's lifting OUFR to top-level, you might need to alter your include or typeRoots to also read the top-level typings.

if i use tsc - instead of tsdx - it builds fine

I'm not sure why tsc works though 🤔 Is that the same way you're running tsdx build?

I do see you're using TS v4 for tsc while tsdx is still on TS v3 (see #926 for details and workaround there)

Your environment

Seems like the command may have ran in the wrong directory since tsdx and typescript versions are not shown.

Sinled commented 3 years ago

@agilgur5 thanks for reply,

i've normalized versions of typescript (explcitly specified 3.9.7 which is used when running tsdx), and tried to run from the same folder

sinled  in ~/dev/Projects/_my/_tmp/test-rushx-tsdx (master●●)
$ cd packages/somelib

sinled in ~/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib (master●●)
$ ./node_modules/.bin/tsc --noEmit false

sinled in ~/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib (master●●)
$ ./node_modules/.bin/tsc -v
Version 3.9.7

sinled at SD-MacBook-Pro in ~/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib (master●●)
$ ./node_modules/.bin/tsdx build
✓ Creating entry file 979 ms
(typescript) Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.
Error: /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/packages/somelib/src/index.tsx(7,10): semantic error TS2305: Module '"../node_modules/office-ui-fabric-react/lib/Styling"' has no exported member 'mergeStyleSets'.
    at error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at throwPluginError (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:11878:12)
    at Object.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:12912:24)
    at Object.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup/1.32.1/node_modules/rollup/dist/shared/node-entry.js:12081:38)
    at RollupContext.error (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:17237:30)
    at /Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25033:23
    at arrayEach (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:545:11)
    at Function.forEach (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:9397:14)
    at printDiagnostics (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25006:12)
    at Object.transform (/Users/sinled/dev/Projects/_my/_tmp/test-rushx-tsdx/common/temp/node_modules/.pnpm/registry.npmjs.org/rollup-plugin-typescript2/0.27.3_rollup@1.32.1+typescript@3.9.7/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:29277:17)

I'm not really sure how rush works but if it's lifting OUFR to top-level, you might need to alter your include or typeRoots to also read the top-level typings.

AFAIK rush hardlinks all dependencies directly to the specific package node_modules

Sinled commented 3 years ago

If anyone stumbled upon this, i've found partial workaround - typecheck with tsc and build with tsdx

"build": "tsc && tsdx build --transpileOnly"
jessekrubin commented 3 years ago

I am having the same issue with material-ui

leohxj commented 2 years ago

I am having the same issue with material-ui

also use rushjs?

jessekrubin commented 2 years ago

I am having the same issue with material-ui

also use rushjs?

Yes I do!

agilgur5 commented 2 years ago

For reference, I am fairly sure I fixed this upstream in https://github.com/ezolenko/rollup-plugin-typescript2/pull/332, which fixed https://github.com/ezolenko/rollup-plugin-typescript2/issues/234, which is a very similar upstream issue with pnpm symlinks.

To use that in your project, you can set your pnpm overrides to use rollup-plugin-typescript2 0.32.0+:

{
  "pnpm": {
    "overrides": {
      "rollup-plugin-typescript2": "^0.32.0"
    }
  }
}