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
Cannot bundle a TS file, which imports JS file from a package using NodeJS conditional exports #911
Comments
@tjenkinson and/or @guybedford sorry for tagging you directly, but you both worked on last big change in the part of code which is responsible for resolving files. |
Hi @bhovhannes could you try removing the lines you mentioned and see if any tests fail? That might help explain the reason for it. On the surface I’m also a bit confused why it gets rewritten there. |
@tjenkinson removing lines failed one test, which was introduced by PR #480, which fixed issue #479. Everywhere it is said that |
well, I found that in TypeScript docs: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#module-identifiers-allow-for-js-extension And the support for that has been Which means the lines cannot be removed I guess. |
Thanks. After looking at the issue and pr I don’t get why it was added. From the screenshots it looks like it might have been to workaround a linter error for extensionless import(?) If typescript really tries to switch an explicit .js extension for a .ts one then I’m baffled. Need to spend more time looking into this. |
Opened a PR to fix here: #921 |
Hi,
@rollup/plugin-node-resolve
13.0.0
2.52.2
macOS Big Sur 11.4
14.15.1
Issue description
Steps to reproduce
git clone
the https://github.com/bhovhannes/rollup-plugin-node-resolve-issue reponpm ci
npm run build
Details
The reproduction link written above is a small Rollup project. Entrypoint -
index.ts
, is in TypeScript. TypeScript does not really matter here, the only thing which matters is the extension of the file -.ts
.Inside an entrypoint file we import a utility function using
import sum from '@abcdef/lib-utils/dist/sum.js'
syntax.The package
@abcdef/lib-utils
has anexports
field in itspackage.json
containing:That makes possible to let Rollup consume
sum.js
fromdist_esm
folder and if the tool does not support ESM (looking on you Jest) it will usesum.js
fromdist
folder.Lines https://github.com/rollup/plugins/blame/master/packages/node-resolve/src/index.js#L148-L155 in
@rollup/plugin-node-resolve
code check for the case when there is a.js
import inside a.ts
file and change extension to.ts
. I'll be grateful for any explanation why this is needed.After that, plugin resolves the package, taking
exports
field into account and ends up withnode_modules/@abcdef/lib-utils/dist_esm/sum.ts
url, which obviously does not exist.Expected Behavior
Build should complete without errors.
Actual Behavior
Build errors out, trying to bundle non-existent TypeScript file. The error:
Additional Information
Removing lines https://github.com/rollup/plugins/blame/master/packages/node-resolve/src/index.js#L148-L155 fixes the issue.
Or, perhaps we can check if the resolved file indeed exists in https://github.com/rollup/plugins/blob/master/packages/node-resolve/src/package/resolvePackageTarget.js#L13 ?
I'll be happy to submit a pull request, just I am not sure in which direction to proceed.
Thanks!
The text was updated successfully, but these errors were encountered: