Skip to content
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

Dynamic import failing with TS5012 and TS6053 #4720

Closed
matt-landers opened this issue Apr 11, 2020 · 2 comments
Closed

Dynamic import failing with TS5012 and TS6053 #4720

matt-landers opened this issue Apr 11, 2020 · 2 comments
Labels
cli related to cli/ dir

Comments

@matt-landers
Copy link

I'm hacking together a simple framework like Next.js for denobyexample.com. I'm using oak as the server framework. In one of my middleware functions, I'm loading modules dynamically like:

const module = await import(`../pages/${path}.tsx`)

This produces the following 2 errors:

Unhandled Error: error TS5012: Cannot read file 'file:///E:/Source/deno/denobyexample.com/pages/test.tsx': Error: assert.
►
error TS6053: File 'file:///E:/Source/deno/denobyexample.com/pages/test.tsx' not found.

If the import is static like:

const module = await import(`../pages/index.tsx`)

Everything works great.

Should this be supported? I saw this PR #4561 and thought it was referencing these types of scenarios.

Thanks for the help!

FYI @kitsonk

@kitsonk
Copy link
Contributor

kitsonk commented Apr 11, 2020

I think it is unrelated to #4561. It is a larger defect that we should have tested for.

It relates to the situation that we statically analyse all imports, so they can be made asynchronously before we invoke the TypeScript compiler (because the compiler only supports synchronous imports). But the preprocessing does account for all statically determinable imports, only those where the string is itself static. So in this case the dynamic import fails. We basically need a backup to when the preprocessing fails, as the preprocessing will always have its limits.

@bartlomieju bartlomieju added the cli related to cli/ dir label May 21, 2020
@bartlomieju
Copy link
Member

Fixed in #5029

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

No branches or pull requests

3 participants