tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

Typings problems in rush monorepo (pnpm hard links)

Open Sinled opened this issue 4 years ago • 7 comments

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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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?

Sinled avatar Jan 12 '21 16:01 Sinled

(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.

agilgur5 avatar Jan 12 '21 23:01 agilgur5

@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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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/[email protected][email protected]/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 avatar Jan 13 '21 10:01 Sinled

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

"build": "tsc && tsdx build --transpileOnly"

Sinled avatar Jan 14 '21 09:01 Sinled

I am having the same issue with material-ui

jessekrubin avatar Jan 16 '21 01:01 jessekrubin

I am having the same issue with material-ui

also use rushjs?

leohxj avatar Apr 07 '22 09:04 leohxj

I am having the same issue with material-ui

also use rushjs?

Yes I do!

jessekrubin avatar Apr 07 '22 18:04 jessekrubin

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"
    }
  }
}

agilgur5 avatar Jun 10 '22 16:06 agilgur5