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

Missing types for programmatic usage with TypeScript and Node #2757

Closed
alshdavid opened this issue Apr 15, 2023 · 5 comments
Closed

Missing types for programmatic usage with TypeScript and Node #2757

alshdavid opened this issue Apr 15, 2023 · 5 comments

Comments

@alshdavid
Copy link

System Info

System:
OS: Linux 4.4 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
Memory: 31.09 GB / 47.91 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 18.12.1 - /usr/local/node-version-manager/bin/node
Yarn: 1.22.19 - /usr/local/node-version-manager/bin/yarn
npm: 9.6.0 - /usr/local/node-version-manager/bin/npm
npmPackages:
@rspack/core: ^0.1.7 => 0.1.7

Details

When trying to use rspack programmatically via node and @rspack/core - I have type errors due to missing internal dependencies.

// index.ts
import * as rspack from '@rspack/core'
console.log(rspack.rspack)
$ npx tsc
../node_modules/.pnpm/@rspack+core@0.1.7/node_modules/@rspack/core/dist/compilation.d.ts:11:24 - error TS7016: Could not find a declaration file for module 'webpack-sources'.
 
'/home/alshdavid/Development/alshdavid/davidalsh-com/node_modules/.pnpm/webpack-sources@3.2.3/node_modules/webpack-sources/lib/index.js' implicitly has an 'any' type.

  Try `npm i --save-dev @types/webpack-sources` if it exists or add a new declaration (.d.ts) file containing `declare module 'webpack-sources';`
../node_modules/.pnpm/@rspack+core@0.1.7/node_modules/@rspack/core/dist/compilation.d.ts:16:8 - error TS1259:
 Module '"/home/alshdavid/Development/alshdavid/davidalsh-com/node_modules/.pnpm/@rspack+core@0.1.7/node_modules/@rspack/core/dist/ResolverFactory"' can only be default-imported using the 'esModuleInterop' flag

and so on

These type dependencies are marked as devDependencies in the package.json

image

However they are not marked as dependencies or peerDependencies of @rspack/core - so tsc fails

I can add these dependencies to my application manually

Reproduce link

No response

Reproduce Steps

mkdir foobar
cd foobar

pnpm init
pnpm install --save typescript @rspack/core

echo "import * as rspack from '@rspack/core'" > main.ts
echo "console.log(rspack.rspack)" >> main.ts

npx tsc --outDir dist --module CommonJS --strict true --target ESNext main.ts

@alshdavid alshdavid added bug Something isn't working pending triage The issue/PR is currently untouched. labels Apr 15, 2023
@alshdavid alshdavid changed the title Missing types for usage from within ts + node Missing types for programmatic usage with TypeScript and Node Apr 15, 2023
@hyf0 hyf0 added p3-has-workaround and removed pending triage The issue/PR is currently untouched. labels Apr 15, 2023
@hyf0
Copy link
Collaborator

hyf0 commented Apr 15, 2023

Did you enable skipLibCheck feature of TypeScipr? You might try compiling with skipLibCheck:true to see if the error still exists.

@alshdavid
Copy link
Author

alshdavid commented Apr 15, 2023

Hey, thanks for the suggestion. That configuration flag does indeed resolve the compilation issue however (I could be wrong but) I believe using skipLibCheck is not considered a best practice as it reduces the accuracy of types obtained from libraries (beyond just rspack). My understanding is that it's normally enabled to resolve type collisions in edge cases rather than a setting expected to be used by default

@hyf0
Copy link
Collaborator

hyf0 commented Apr 15, 2023

I believe using skipLibCheck is not considered a best practice as

I agree with you. So you might take skipLibCheck: true as a workaround. Currently, we are the focus on #2048 and lack manpower

But we have planned to pre-compile dependencies of Rspack, which should solve this problem.

Thanks for your feedback. It's very useful for us to decide which parts we should concentrate on in the future.

@alshdavid
Copy link
Author

alshdavid commented Apr 15, 2023

But we have planned to pre-compile dependencies of Rspack, which should solve this problem.

That's perfect, thanks for taking the time to respond!

@chenjiahan
Copy link
Member

Tacked in #6481 and #5867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants