Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support preserveSymlinks from tsconfig.json #69

Closed
1 of 2 tasks
jrson83 opened this issue Jun 23, 2024 · 3 comments · Fixed by #71
Closed
1 of 2 tasks

Support preserveSymlinks from tsconfig.json #69

jrson83 opened this issue Jun 23, 2024 · 3 comments · Fixed by #71
Labels
bug Something isn't working released

Comments

@jrson83
Copy link
Contributor

jrson83 commented Jun 23, 2024

Problem

This might be more a feature request then a bug report.

This issue is related to rollup-plugin-dts Swatinem/rollup-plugin-dts#143 which has not been solved.

As described in the issue, the plugin is not able to resolve Vue3 types from PNPM symlinks (default configuration).

As commented Swatinem/rollup-plugin-dts#143 (comment), the issue has not been fixed/solved, because it can be overcome setting preserveSymlinks: false, you have 3 options.

Workaround using tsconfig.json:

"compilerOptions": {
  "preserveSymlinks": false
}

Workaround using rollup.config plugins:

import dts from 'rollup-plugin-dts'
// rollup.config.ts
plugins: [
  dts({
   compilerOptions: {
      preserveSymlinks: false
    }
  })
]

Another workaround is using shamefully-hoist in .npmrc.

ignore-workspace-root-check=true
shamefully-hoist=true
node-linker=hoisted

Workarounds:

  • The tsconfig.json workaround does not work, because pkgroll does not care about preserveSymlinks.
  • The rollup.config workaround can't be used, because you can't configure rollup plugins with pkgroll.
  • The .npmrc workaround is really annoying because it actually disables all pnpm benefits.

Build-Error:

packages/vue build$ pkgroll --clean-dist --target=es2020 --minify
packages/vue build: src/index.ts(2,10): error TS2305: Module '"vue"' has no exported member 'defineComponent'.
packages/vue build: src/index.ts(2,27): error TS2305: Module '"vue"' has no exported member 'h'.
packages/vue build: src/index.ts(8,9): error TS7006: Parameter 'props' implicitly has an 'any' type.
packages/vue build: Error [RollupError]: [plugin dts] src/index.ts: Failed to compile. Check the logs above.
packages/vue build:     at getRollupError (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/shared/parseAst.js:282:41)
packages/vue build:     at Object.error (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/shared/parseAst.js:278:42)
packages/vue build:     at Object.error (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/shared/rollup.js:804:32)
packages/vue build:     at Object.error (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/shared/rollup.js:19790:42)
packages/vue build:     at generateDtsFromTs (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/pkgroll@2.1.1_typescript@5.5.2/node_modules/pkgroll/dist/rollup-plugin-dts-BzOer96X.js:30:1744)
packages/vue build:     at Object.transform (/home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/pkgroll@2.1.1_typescript@5.5.2/node_modules/pkgroll/dist/rollup-plugin-dts-BzOer96X.js:30:1852)
packages/vue build:     at /home/dev/typescript-dev/begin/pkgroll-issue/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/shared/rollup.js:989:40 {
packages/vue build:   id: '/home/dev/typescript-dev/begin/pkgroll-issue/packages/vue/src/index.ts',
packages/vue build:   hook: 'transform',
packages/vue build:   code: 'PLUGIN_ERROR',
packages/vue build:   plugin: 'dts',
packages/vue build:   watchFiles: [
packages/vue build:     '/home/dev/typescript-dev/begin/pkgroll-issue/packages/vue/src/index.ts'
packages/vue build:   ],
packages/vue build:   [Symbol(augmented)]: true
packages/vue build: }
packages/vue build: Failed
/home/dev/typescript-dev/begin/pkgroll-issue/packages/vue:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @pkgroll-issue/vue@0.0.1 build: `pkgroll --clean-dist --target=es2020 --minify`
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.

Expected behavior

I expect pkgroll to pick-up compilerOptions.preserveSymlinks from tsconfig.json, to resolve the issue, but it doesn't.

Possible solutions

For testing I edited node_modules/pkgroll/dist/cli.js line 37 compilerOptions:{composite:!1,preserveSymlinks:!1}. This solves the issue.

pkgroll@2.1.1.patch

So a solution would be to check for and add preserveSymlinks here:

https://github.com/privatenumber/pkgroll/blob/46c38750a44992f9977471819f4bfa0ef2039639/src/utils/get-rollup-configs.ts#L66C6-L66C21

Minimal reproduction URL

https://github.com/jrson83/pkgroll-issue

Version

v2.1.1

Node.js version

v21.7.2

Package manager

pnpm

Operating system

Linux

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work financially will speed up resolution

  • I'm willing to offer financial support
@jrson83 jrson83 added the bug Something isn't working label Jun 23, 2024
@privatenumber
Copy link
Owner

Are there any side effects to enabling preserveSymlinks all the time? If not, we can add it like we did with composite.

@jrson83
Copy link
Contributor Author

jrson83 commented Jun 25, 2024

I did some more research and found more issues in several repositories on this apparently very complex topic.

This PR is very helpful, in addition this very precise explanation of the problem and the solution:

Quote:

false is actually the default of resolve, Rollup itself, TS itself, which all reflect how Node itself treats symlinks (i.e. require.resolve).


If not, we can add it like we did with composite.

This would be a solution that unbuild has also implemented with this PR:


Another thing we could try is following this PR (and also several rollup/esbuild related plugins):

The solution here is linked in the source code:

https://github.com/microsoft/TypeScript/blob/c219989232a9db9fb6a5057dd34e21acc628a3b1/src/compiler/sys.ts#L1488-L1490

We could try here:

fs.realpathSync.native(stripQuery(chunk.facadeModuleId!))
.slice(sourceDirectoryPath.length, -srcExtension.length)

@privatenumber maybe we could create a small test which fails the current issue, in order to try if implementing the condition solves the problem. This sounds like a cleaner solution to me.

If it is to complex we could just go with default value false.

@privatenumber
Copy link
Owner

🎉 This issue has been resolved in version 2.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants