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

[Build Error] The requested module 'x' does not provide an export named 'default' #8660

Closed
1 task
raulfdm opened this issue Sep 25, 2023 · 12 comments
Closed
1 task
Labels
needs triage Issue needs to be triaged

Comments

@raulfdm
Copy link
Contributor

raulfdm commented Sep 25, 2023

Astro Info

Astro                    v3.1.2
Node                     v18.15.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

Not relevant

Describe the Bug

I'm trying to create an Astro project that uses three.js and its ecosystem, and when I tried to import a lib called lil-gui, while in dev, it works fine, it gets broken running a build:

 error   The requested module 'lil-gui' does not provide an export named 'default'
file:///Users/raulmelo/development/sandbox/test-lil-gui/dist/chunks/pages/script_d5fa1c97.mjs:1
import GUI from 'lil-gui';
       ^^^
SyntaxError: The requested module 'lil-gui' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

I noticed that if I edit the dependency package.json adding a "exports" property, it works fine:

  "exports":{
    ".":{
      "import": "./dist/lil-gui.esm.js",
      "require": "./dist/lil-gui.umd.js"
    }
  }

My question here is: is there anything we need to do on Astro's/Vite's config to fix that?

What's the expected result?

To build without error.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-geagbm?file=README.md

Participation

  • I am willing to submit a pull request for this issue.
@raulfdm
Copy link
Contributor Author

raulfdm commented Sep 25, 2023

CleanShot.2023-09-25.at.07.51.38.mp4

@bluwy
Copy link
Member

bluwy commented Sep 25, 2023

Sorry you're hitting this. Unfortunately it's a Vite bug, see vitejs/vite#10712 and vitejs/vite#14332 (and probably more). I'm planning to fix this in Vite 5, but for now there's not much Astro can do.

As a workaround, you can import it like this:

import * as _GUI from 'lil-gui'
const GUI = GUI.default
// or (not sure if the above is enough)
const GUI = GUI.default || GUI

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2023
@raulfdm
Copy link
Contributor Author

raulfdm commented Sep 26, 2023

Oh.. nice @bluwy ... thanks getting me back and for the workaround 🙏

@raulfdm
Copy link
Contributor Author

raulfdm commented Sep 26, 2023

For further reference:

I noticed that in one if the open issues, a guy posted this: https://vite-plugin-ssr.com/broken-npm-package

I tried the following vite-config:

import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
  vite: {
    ssr: {
      // Add npm packages containing invalid code here
      noExternal: ["lil-gui"],
    },
  },
});

and the build succeeded:

CleanShot 2023-09-26 at 10 44 05

Also running a live server on dist, it worked fine.

@kitschpatrol
Copy link
Contributor

Thanks for this tip. For some reason I just ran into this error in for the first time after upgrading from Astro 4.6.3 → 4.8.3.

It's happening in production builds only, with complaints about a missing a default export on nanoid, which I'm only importing in Svelte components.

Here's the stack trace from the failed build:

15:48:11 [vite] ✓ built in 2.31s

 generating static routes 
2024-05-13T19:48:11.245Z astro:telemetry {
  context: {
    isGit: true,
    anonymousProjectId: '75d034b7c4fdc0dd0c1a22fcc8e69f50a50246f53fd192f5439f041340098812',
    packageManager: 'pnpm',
    packageManagerVersion: '9.1.1',
    anonymousId: 'a027c6f6f986bd6de11997d886abe7d1516be0d79855f6aa6df802f6fe46a496',
    anonymousSessionId: 'aaa25d967446653ca4eeab4994b492146a9b3d0c60d9dc0c777008fb12890b2d'
  },
  meta: {
    nodeVersion: '20.13.1',
    viteVersion: '5.2.11',
    astroVersion: '4.8.3',
    systemPlatform: 'darwin',
    systemRelease: '23.4.0',
    systemArchitecture: 'arm64',
    cpuCount: 14,
    cpuModel: 'Apple M3 Max',
    cpuSpeed: 2400,
    memoryInMb: 36864,
    isDocker: false,
    isTTY: undefined,
    isWSL: false,
    isCI: false,
    ciName: null
  }
}
2024-05-13T19:48:11.245Z astro:telemetry [
  {
    "eventName": "ASTRO_CLI_ERROR",
    "payload": {
      "name": "SyntaxError",
      "cliCommand": "build",
      "isFatal": true,
      "anonymousMessageHint": "The requested module"
    }
  }
]
The requested module 'nanoid/non-secure' does not provide an export named 'default'
  Stack trace:
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async generatePages (file:///Users/mika/Code/svelte-tweakpane-ui/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/astro/dist/core/build/generate.js:120:7)
    at async AstroBuilder.build (file:///Users/mika/Code/svelte-tweakpane-ui/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/astro/dist/core/build/index.js:133:5)
    at async build (file:///Users/mika/Code/svelte-tweakpane-ui/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/astro/dist/core/build/index.js:45:3)
    at async runCommand (file:///Users/mika/Code/svelte-tweakpane-ui/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/astro/dist/cli/index.js:140:7)
 ELIFECYCLE  Command failed with exit code 1.


Adding the following to my Astro config fixed it:
vite: {
  ssr: {
    noExternal: ['nanoid']
  }
}

@scarletczen
Copy link

Anyone getting this issue again? Build is failing only on CI, and the astro config workaround is not working.
image

@rrscodes
Copy link

@scarletczen Yes the same is happening for me since yesterday evening and the workaround is not helpful.

@gilbertoxdev
Copy link

Anyone getting this issue again? Build is failing only on CI, and the astro config workaround is not working. image

I have the same error and have not found a solution.

@gilbertoxdev
Copy link

The solution is installing npm install @iconify/tools --save

@scarletczen
Copy link

The solution is installing npm install @iconify/tools --save

Tried, but did not help

@maximgx
Copy link

maximgx commented Aug 13, 2024

The solution is installing npm install @iconify/tools --save

Tried, but did not help

didn't, because when you install as per his suggestion you end up with two versions of @iconify/tools --save

and astro continues to pick the old one, you must remove the old one – for me it worked

in production unfortunately, the workaround is rm -rdf node_modules/.pnpm/@[email protected] && npm run build

@scarletczen
Copy link

The solution is installing npm install @iconify/tools --save

Tried, but did not help

didn't, because when you install as per his suggestion you end up with two versions of @iconify/tools --save

and astro continues to pick the old one, you must remove the old one – for me it worked

in production unfortunately, the workaround is rm -rdf node_modules/.pnpm/@[email protected] && npm run build

Thank you, this workaround did help in production, however I'm not sure why this error would pop up all of a sudden on a fine weekend,

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

No branches or pull requests

7 participants