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

SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries #74

Closed
stevehollaar opened this issue Dec 1, 2021 · 7 comments · Fixed by #2312
Labels
bug Something isn't working transpiler parser || printer

Comments

@stevehollaar
Copy link

stevehollaar commented Dec 1, 2021

Hello!
I'm hitting the following while trying bun on an existing nextjs project. Any suggestions on how to debug?

bun
[0.12ms] "node_modules.bun" - 1933 modules, 130 packages
[0.03ms] ".env.development"
[3.00ms] Bun!! v0.0.52


  Link: http://localhost:3001


[0.06ms] "node_modules.server.bun" - 1938 modules, 131 packages
[0.00ms] ".env.development"
[91.62ms] Next.js ready! (powered by Bun)
75 |         console.error(err);
76 |     });
77 |     addEventListener("fetch", async (event) => {
78 |       var route = Bun.match(event);
79 |
80 |       const PageNamespace = await import(route.filePath);
                                      ^
 SyntaxError: Indirectly exported binding name 'default' cannot be resolved by star export entries.
      at (anonymous) (http://localhost:3001/blob:node_modules.server.bun:80:34)
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Dec 2, 2021

This is most likely a CommonJS <> ESM interop issue.

If you use require or module.exports in your code along with export * from it has issues with HMR because CommonJS is exported as export default commonJS(() => codeInhere). This is Bun's fault and needs to be fixed, but I haven't been able to prioritize it yet.

For now, try replacing usages of export * from that point to a CommonJS module with an import and re-export manually, like this:

// Instead of this
export * from 'lodash';

// Try this
import {camelCase} from 'lodash';

export {camelCase};

You can find where export * from is used by grepping for it:

git grep "export \* from"

This only applies to app code. Running bun bun --use next bundles dependencies and export * from should work great in any node_modules you're using.

If that doesn't work

Try starting Bun without SSR/pre-rendering enabled:

bun --disable-bun.js

This disables Bun's JavaScript runtime environment from trying to render your Next.js pages into HTML. It will make it a little slower to show pages on start and mean any code in getStaticProps or getServerSideProps won't be executed.

@Jarred-Sumner Jarred-Sumner added bug Something isn't working transpiler parser || printer esm<>cjs labels Dec 2, 2021
@stevehollaar
Copy link
Author

Thanks for the help!
Unfortunately, I don't have any CommonJS usage in my next.js code. I replaced all usages of export * with export { foo }, just to see, however I get the same behaviour.

bun --disable-bun.js also misbehaves, giving me a blank screen with no feedback in the browser or console.
I suspect there must be something in my dependencies that bun dislikes, as a clean project works just fine

@Electroid Electroid removed the esm<>cjs label Nov 3, 2022
shiny added a commit to tealight-uk/wilson that referenced this issue Aug 4, 2023
@The-Code-Monkey
Copy link

@Jarred-Sumner I seem to be hitting this issue but not during build, only when running bun test

@morgante
Copy link

I'm also encountering this during tests.

@valgaze
Copy link

valgaze commented Nov 26, 2023

Could also be related type-only import/exports, ex

Error ❌

export { SurveyQuestion, SurveyQuestionType } from "./cards";

vs Working ✅

export type { SurveyQuestion, SurveyQuestionType } from "./cards";

@ChuckJonas
Copy link

ChuckJonas commented Dec 19, 2023

I just ran into this with bun and the above comment fixed it. In my case I have to split my exports out to two different statements, which is a bit annoying:

export { AssistantDefinition, definition } from "./definition";
//ERR: SyntaxError: Indirectly exported binding name 'AssistantDefinition' is not found.
export { definition } from "./definition";
export type { AssistantDefinition } from "./definition";

@plepisnew
Copy link

Could also be related type-only import/exports, ex

Error ❌

export { SurveyQuestion, SurveyQuestionType } from "./cards";

vs Working ✅

export type { SurveyQuestion, SurveyQuestionType } from "./cards";

You are an angel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transpiler parser || printer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants