-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
@rollup/plugin-typescript does not resolve modules that use conditional exports when moduleResolution is set to node16 #1224
Comments
Note that this could be caused by |
I don't think this problem is related to conditional exports. If I change the package.json in the provided demo to contain the following exports property, I get the same error:
I'm experiencing a similar (or the same?) problem in my project. I've added some console logs to It seems to finds the package.json, but does not seem to be able to use the information to resolve the location of the type information. I've tried with 69 function createModuleResolver(ts, host) {
70 const compilerOptions = host.getCompilationSettings();
71 const cache = ts.createModuleResolutionCache(process.cwd(), host.getCanonicalFileName, compilerOptions);
72 const moduleHost = Object.assign(Object.assign({}, ts.sys), host);
73 return (moduleName, containingFile) => {
74 const resolved = ts.nodeModuleNameResolver(moduleName, containingFile, compilerOptions, moduleHost, cache);
75 if (moduleName.startsWith('dependency')) {
76 console.log({moduleName, containingFile, resolved});
77 }
78 return resolved.resolvedModule;
79 };
80 } |
That's definitely the same issue - the |
Ah, my bad, I thought it's only called Conditional Exports when it contains different exports for import/require. |
Typescript also exports a function resolveModuleName. It has the same signature* as If I replace ts.nodeModuleNameResolver(...) with This function seems to exist for years, and definitely exists in the currently required version v4.2.2. (*resolveModuleName takes an extra argument |
And here seems to be a PR that fixes this: #1194 :) |
With v8.5.0 this now works for me, but only if I set the tsconfig module property to |
Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it. ⓘ |
typescript
8.3.3
2.77.0
16.14.0
Expected Behavior
Both
tsc
androllup -c
successfully find typescript declarations.Actual Behavior
tsc
compiles successfully, butrollup -c
does not - it fails to find the type declarations for thedependency
dependency.Additional Information
The
package.json
in the included dependency uses Conditional Exports to specify the location of type declaration files for the module: https://github.com/apottere/rollup-typescript-reproduction/blob/main/dependency/package.json#L4-L10In the main package,
tsconfig.compilerOptions.moduleResolution
is set tonode16
: https://github.com/apottere/rollup-typescript-reproduction/blob/main/tsconfig.json#L9This is correct AFAICT according to the Typescript 4.7 release notes, and
tsc
can find the declarations and compile the script just fine. For some reasonrollup -c
cannot, and throws the following error:I did a little digging in the module resolution code in the rollup plugin, and it seems like adding
"main": "./build/types/",
to the dependency'spackage.json
allows rollup to successfully build the bundle, but that's obviously not a great solution. I wasn't able to figure out anything more than that though.The text was updated successfully, but these errors were encountered: