-
-
Notifications
You must be signed in to change notification settings - Fork 626
Description
Hi,
- Rollup Plugin Name:
@rollup/plugin-node-resolve - Rollup Plugin Version:
13.0.0 - Rollup Version:
2.52.2 - Operating System (or Browser):
macOS Big Sur 11.4 - Node Version:
14.15.1 - Link to reproduction (
⚠️ read below): https://github.com/bhovhannes/rollup-plugin-node-resolve-issue
Issue description
Steps to reproduce
git clonethe https://github.com/bhovhannes/rollup-plugin-node-resolve-issue repo- run
npm ci - run
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 an exports field in its package.json containing:
"exports": {
"./dist/*": {
"import": "./dist_esm/*",
"require": "./dist/*"
}
}
That makes possible to let Rollup consume sum.js from dist_esm folder and if the tool does not support ESM (looking on you Jest) it will use sum.js from dist 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 with node_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:
Error: Could not load /Users/hovhannesbabayan/Projects/github/bhovhannes/
rollup-plugin-node-resolve-issue/node_modules/@abcdef/lib-utils/dist_esm/sum.ts (imported by input.ts):
ENOENT: no such file or directory, open '/Users/hovhannesbabayan/Projects/github/bhovhannes/
rollup-plugin-node-resolve-issue/node_modules/@abcdef/lib-utils/dist_esm/sum.ts'
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!