nuxt / nuxt/nuxt

Nuxt module dynamic imports not working in build mode

Open
#27,296 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bundler:vite pending triage
Dominant language
TypeScript
Stars
60.9k
Forks
5.8k
Avg merge
7h 8m
Merged PRs (30d)
162

Description

Environment

  • Operating System: Darwin
  • Node Version: v18.12.1
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: yarn@1.22.19
  • Builder: -
  • User Config: devtools, modules
  • Runtime Modules: define-async-module-issue@1.0.1
  • Build Modules: -

Reproduction
Github:

module: https://www.npmjs.com/package/define-async-module-issue?activeTab=code
root: https://github.com/RomanSkrypnik/define-async-comp-issue

Video:

dev ( works fine): Screencast 2024-05-21 20-59-14.webm
build: Screencast 2024-05-21 21-00-05.webm

Describe the bug

Cannot use dynamic import from nuxt module if it's used as npm package:
image
image
In dev mode and playground everything works fine but build one doesn't
As I understand, the problem is path - in build mode nuxt creates the path relative to host
For example: http://localhost:3000/components/Test.vue

Additional context

No response

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked define-async-comp-issue reproduction and compare its working dev-mode behavior with the failing build output. Trace how the Nuxt module's dynamic import path is generated during build mode; done means the npm-installed module resolves its component correctly in a production build.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, nuxt
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.