For some reason, I have to write code like this:
import { something } from '/Users/my-user-name/my-working-dir/my-package/src/somefile.ts';
Rollup sees /Users
thinks that's a node_modules, but not.
I can't find any rollup plugin related to this.
Now, I've written a rollup plugin to fix this, but I didn't write any plugin before, I don't know if I'm doing it right or wrong, but the output is exactly what I want:
function fixLocalImport() {
return {
name: 'fix-local-import', // this name will show up in warnings and errors
resolveId(source, importer) {
if (source.startsWith('/Users')) {
return source;
}
return null; // other ids should be handled as usually
},
load(id) {
return null; // other ids should be handled as usually
}
};
}
Am I doing anything wrong?
Rollup doesn't automatically handle absolute URLs, since they refer to different things depending on the context (either the root of your website server, or the root of your file system, or the root of your project). Writing a plugin is the best solution here, although you don't need to override the "load" hook.
function fixLocalImport() {
return {
name: 'fix-local-import',
resolveId(source, importer) {
if (source.startsWith('/Users')) {
return source;
}
return null;
},
};
}