Hi,
Issue description
Steps to reproduce
git clone the 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!
Hi,
@rollup/plugin-node-resolve13.0.02.52.2macOS Big Sur 11.414.15.1Issue description
Steps to reproduce
git clonethe https://github.com/bhovhannes/rollup-plugin-node-resolve-issue reponpm cinpm run buildDetails
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-utilshas anexportsfield in itspackage.jsoncontaining:That makes possible to let Rollup consume
sum.jsfromdist_esmfolder and if the tool does not support ESM (looking on you Jest) it will usesum.jsfromdistfolder.Lines https://github.com/rollup/plugins/blame/master/packages/node-resolve/src/index.js#L148-L155 in
@rollup/plugin-node-resolvecode check for the case when there is a.jsimport inside a.tsfile and change extension to.ts. I'll be grateful for any explanation why this is needed.After that, plugin resolves the package, taking
exportsfield into account and ends up withnode_modules/@abcdef/lib-utils/dist_esm/sum.tsurl, 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!