Open ko22009 opened 1 year ago
You'll need to be more specific than that, this is barely any more descriptive than just "doesn't work".
Try use alias with fonts or images.
k not sure this is a use case that can be supported, not even sure how it's supposed to work without a path alias. are you using some custom loader with webpack or sth?
I use @rollup/plugin-url, it's great plugin.
After upgrading Rollup from v2 to v3 and commonjs plugin, I'm having an issue with loading .js
files from a .ts
file. The resolveId
return value is /Users/<user>/<project>/Users/<user>/<project>/src/js-file.js
with 2 full paths.
{
errno: -2,
code: 'PLUGIN_ERROR',
syscall: 'open',
path: '/Users/<user>/<project>/Users/<user>/<project>/src/js-file.js',
pluginCode: 'ENOENT',
plugin: 'commonjs--resolver',
hook: 'resolveId',
watchFiles: [
'/Users/<user>/<project>/src/file.ts',
'/Users/<user>/<project>/Users/<user>/<project>/src/js-file.js'
]
}
A few things I observed:
outDir
is read from the config instead of from compilerOptions
https://github.com/simonhaenisch/rollup-plugin-typescript-paths/blob/master/index.ts#L12 - so it always defaults to '.'
path.join('.', '/abs/path')
becomes 'abs/path'
.This was the exact behavior with rollup v2 (the double path) but now it's actually failing, specifically with .js
files.
@elado, allowJS: true in your tsconfif file?
Yes. with allowJS
Ok cool I wasn't aware that Rollup has released a v3 yet (not actively working with Rollup anymore at the moment).
https://rollupjs.org/migration/#changes-to-the-plugin-api looks like there were some plugin API changes so until I have a closer look I'm not sure it's currently compatible with v3.
Sorry @elado just read your message properly... can you maybe try a patch in your project by opening node_modules/rollup-plugin-typescript-paths/dist/index.js
, and in line 19 at the end change
outDir = _g.outDir
to
outDir = _g.compilerOptions.outDir
(at least I think that's the fix you were suggesting?)
:pray:
This doesn't change much - path.join('dist', '/abs/path')
just spits dist/abs/path
. So I'm not really sure how the malformed returned value is resolved by rollup.
What I wonder is why you'd get an absolute path in the first place... usually import paths are always relative?
Any update? It is also impossible to use rollup-plugin-svelte
together with this plugin. Build fails with error:
Error: Could not load /Users/<user>/<project>/Users/<user>/<project>/node_modules/svelte/index.mjs (imported by test.svelte): ENOENT: no such file or directory, open '/Users/<user>/<project>/Users/<user>/<project>/node_modules/svelte/index.mjs'
Just from having a quick look at this again, it seems like using path.join
here
is ~incorrect~ not always correct? it should instead use path.relative
or sth to find the relative path from outDir
to the resolved file?
If anyone could try that I'm happy to fix it. I just don't have any test case to reproduce, a PR just creating a repro test case would also greatly help with it.
Thanks for quick response. path.relative
did the job and works like a charm for my setting:
{
preserveExtensions: true,
nonRelative: true,
}
Ok cool, thanks for testing that! Just to confirm, you just switched out join
with relative
and that did the trick?
Exactly.
const targetFileName = path.relative(
outDir,
preserveExtensions ? resolvedFileName : resolvedFileName.replace(/\.tsx?$/i, '.js'),
);
I use alias for assets, it doesn't work.