Skip to content

didn't load non ts file #14

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

Open
ko22009 opened this issue Feb 21, 2023 · 16 comments
Open

didn't load non ts file #14

ko22009 opened this issue Feb 21, 2023 · 16 comments

Comments

@ko22009
Copy link

ko22009 commented Feb 21, 2023

I use alias for assets, it doesn't work.

@simonhaenisch
Copy link
Owner

You'll need to be more specific than that, this is barely any more descriptive than just "doesn't work".

@ko22009
Copy link
Author

ko22009 commented Feb 22, 2023

Try use alias with fonts or images.

@simonhaenisch
Copy link
Owner

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?

@ko22009
Copy link
Author

ko22009 commented Feb 22, 2023

I use @rollup/plugin-url, it's great plugin.

@elado
Copy link

elado commented Feb 25, 2023

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:

This was the exact behavior with rollup v2 (the double path) but now it's actually failing, specifically with .js files.

@ko22009
Copy link
Author

ko22009 commented Feb 25, 2023

@elado, allowJS: true in your tsconfif file?

@elado
Copy link

elado commented Feb 25, 2023

Yes. with allowJS

@simonhaenisch
Copy link
Owner

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.

@simonhaenisch
Copy link
Owner

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?)

🙏

@elado
Copy link

elado commented Mar 1, 2023

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.

@simonhaenisch
Copy link
Owner

What I wonder is why you'd get an absolute path in the first place... usually import paths are always relative?

@mdorda
Copy link

mdorda commented Jun 16, 2023

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'

@simonhaenisch
Copy link
Owner

simonhaenisch commented Jun 19, 2023

Just from having a quick look at this again, it seems like using path.join here

const targetFileName = join(
outDir,
preserveExtensions ? resolvedFileName : resolvedFileName.replace(/\.tsx?$/i, '.js'),
);

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.

@mdorda
Copy link

mdorda commented Jun 19, 2023

Thanks for quick response. path.relative did the job and works like a charm for my setting:

{
        preserveExtensions: true,
        nonRelative: true,
}

@simonhaenisch
Copy link
Owner

Ok cool, thanks for testing that! Just to confirm, you just switched out join with relative and that did the trick?

@mdorda
Copy link

mdorda commented Jun 20, 2023

Exactly.

const targetFileName = path.relative( 
 	outDir, 
 	preserveExtensions ? resolvedFileName : resolvedFileName.replace(/\.tsx?$/i, '.js'), 
 ); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants