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

fix(cloudflare): import notImplemented using a relative path #356

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Dec 2, 2024

This was trigering the following error:

-> % npx wrangler dev

 ⛅️ wrangler 3.91.0
-------------------


✘ [ERROR] Build failed with 1 error:

  ✘ [ERROR] Could not resolve "src/runtime/_internal/utils"
  
  
  node_modules/.pnpm/unenv@file+..+unenv/node_modules/unenv/runtime/node/module/$cloudflare.mjs:53:31:
        53 │ import { notImplemented } from "src/runtime/_internal/utils";
           ╵                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
    You can mark the path "src/runtime/_internal/utils" as external to exclude it from the bundle,
  which will remove this error.
  

edits:

@vicb vicb requested a review from a team as a code owner December 2, 2024 09:37
@vicb vicb requested a review from pi0 December 2, 2024 09:39
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only case of this kind of import?

I assume that there is some tsconfig.json setting to make src based imports work within this repo? (Perhaps baseUrl - https://github.com/unjs/unenv/blob/main/tsconfig.json#L3?)

If there is stuff like that going on in the repo, I would expect there to be some transpilation happening when the package is compiled to JS that would update these imports to work in vanilla node? Why didn't that happen? Perhaps an alternative fix would be to ensure that unenv's build step fixes these imports automatically?

@vicb
Copy link
Contributor Author

vicb commented Dec 2, 2024

Is this the only case of this kind of import?

yes - I amended the description, you might not have seen it, that's something I introduced last week.
Existing import are relative.

I assume that there is some tsconfig.json setting to make src based imports work within this repo? (Perhaps baseUrl - https://github.com/unjs/unenv/blob/main/tsconfig.json#L3?)

If there is stuff like that going on in the repo, I would expect there to be some transpilation happening when the package is compiled to JS that would update these imports to work in vanilla node? Why didn't that happen? Perhaps an alternative fix would be to ensure that unenv's build step fixes these imports automatically?

As of before this PR, the transpiled code (in dist/) would contain import { notImplemented } from "src/runtime/_internal/utils"; which is not a valid path.

It should be possible to detect that at build time, I'll create an issue. For now, let's merge the fix if it looks ok.

@petebacondarwin
Copy link
Contributor

It should be possible to detect that at build time, I'll create an issue. For now, let's merge the fix if it looks ok.
👍

@pi0 pi0 merged commit be8b735 into main Dec 2, 2024
2 checks passed
@pi0 pi0 deleted the cf-module branch December 2, 2024 10:07
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

Successfully merging this pull request may close these issues.

3 participants