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

refactor(nuxt): import useNitroApp from subpath #22785

Merged
merged 1 commit into from Aug 24, 2023
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Aug 24, 2023

πŸ”— Linked issue

#18789 (comment)

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This ensures we import useNitroApp from correct path to avoid chunk issue with rollup.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Aug 24, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@@ -2,7 +2,8 @@ import { joinURL, withQuery } from 'ufo'
import type { NitroErrorHandler } from 'nitropack'
import type { H3Error } from 'h3'
import { getRequestHeaders, send, setResponseHeader, setResponseStatus } from 'h3'
import { useNitroApp, useRuntimeConfig } from '#internal/nitro'
import { useRuntimeConfig } from '#internal/nitro'
import { useNitroApp } from '#internal/nitro/app'
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried with import { useNitroApp } from '#imports'? it should be safer to not introduce internal dependencies.

Copy link
Member Author

@danielroe danielroe Aug 24, 2023

Choose a reason for hiding this comment

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

This isn't introducing a dependency - we already import useNitroApp elsewhere from this path.

Using #imports in the Nuxt source code means we don't get type support. (This is soluble but requires a bit of work.)

Copy link
Member

Choose a reason for hiding this comment

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

I would appreciate if we can try to avoid internal imports also for other places sooner πŸ™πŸΌ (We can internally add type back I guess, from one place)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a bit confused. I removed this very import but you then said we didn't need to remove it, here:

#20391 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, I agree supporting #imports would be nice internally. πŸ‘

I'll go ahead and merge this PR as it doesn't change internal situation and we can look to move safely to #imports at any point after that.

@danielroe danielroe merged commit 53f7c1d into main Aug 24, 2023
26 checks passed
@danielroe danielroe deleted the refactor/nitro-export branch August 24, 2023 12:45
@github-actions github-actions bot mentioned this pull request Aug 24, 2023
@fabianwohlfart
Copy link

Hi guys, I still get this error in 3.7.0 with a fresh installation #18789 (comment)

server/api/test.js

export default defineEventHandler(async (event) => {
  const nitroApp = useNitroApp()
  console.log(nitroApp)
})

log

yarn run v1.22.19
$ nuxt build
Nuxt 3.7.0 with Nitro 2.6.1                                                                                             11:50:51
β„Ή Building client...                                                                                                   11:50:55
β„Ή vite v4.4.9 building for production...                                                                               11:50:55
β„Ή βœ“ 97 modules transformed.                                                                                            11:50:58
β„Ή .nuxt/dist/client/manifest.json                   1.59 kB β”‚ gzip:  0.31 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/error-500.c5df6088.css    1.95 kB β”‚ gzip:  0.74 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/error-404.7fc72018.css    3.63 kB β”‚ gzip:  1.12 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/entry.3c4ebcd6.css       12.13 kB β”‚ gzip:  2.49 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/error-500.4f6d91cd.js     1.88 kB β”‚ gzip:  0.99 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/error-404.9afca3df.js     6.53 kB β”‚ gzip:  2.90 kB                                           11:50:58
β„Ή .nuxt/dist/client/_nuxt/entry.bacd57fa.js       197.71 kB β”‚ gzip: 55.62 kB                                           11:50:58
β„Ή βœ“ built in 2.79s                                                                                                     11:50:58
βœ” Client built in 2819ms                                                                                               11:50:58
β„Ή Building server...                                                                                                   11:50:58
β„Ή vite v4.4.9 building SSR bundle for production...                                                                    11:50:58
β„Ή βœ“ 46 modules transformed.                                                                                            11:51:00
β„Ή .nuxt/dist/server/_nuxt/entry-styles.8755339a.mjs             0.08 kB                                                11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-404-styles.1e0dde27.mjs         0.15 kB                                                11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-500-styles.cf4b3e80.mjs         0.15 kB                                                11:51:00
β„Ή .nuxt/dist/server/styles.mjs                                  0.46 kB                                                11:51:00
β„Ή .nuxt/dist/server/_nuxt/island-renderer-9ab8e6f6.js           1.02 kB β”‚ map:   1.43 kB                               11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-500-styles-1.mjs-8fa81fcc.js    2.17 kB β”‚ map:   0.12 kB                               11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-500-4bed7d81.js                 3.00 kB β”‚ map:   3.77 kB                               11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-404-styles-1.mjs-e0837f4f.js    3.86 kB β”‚ map:   0.12 kB                               11:51:00
β„Ή .nuxt/dist/server/_nuxt/error-404-d4bb2e80.js                 9.67 kB β”‚ map:  18.97 kB                               11:51:00
β„Ή .nuxt/dist/server/_nuxt/entry-styles-1.mjs-8b8449e7.js       12.38 kB β”‚ map:   0.11 kB                               11:51:00
β„Ή .nuxt/dist/server/server.mjs                                120.81 kB β”‚ map: 164.17 kB                               11:51:00
β„Ή βœ“ built in 1.68s                                                                                                     11:51:00
βœ” Server built in 1708ms                                                                                               11:51:00
βœ” Generated public .output/public                                                                                nitro 11:51:00
β„Ή Building Nitro Server (preset: node-server)                                                                    nitro 11:51:00
Export "useNitroApp" of module "node_modules/nitropack/dist/runtime/app.mjs" was reexported through module "node_modules/nitropack/dist/runtime/index.mjs" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
Either change the import in "server/api/test.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
βœ” Nitro server built                                                                                             nitro 11:51:05
  β”œβ”€ .output/server/chunks/app/_nuxt/entry-styles.8755339a.mjs (12.4 kB) (2.61 kB gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/entry-styles.8755339a.mjs.map (312 B) (202 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-404-d4bb2e80.mjs (9.81 kB) (3.12 kB gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-404-d4bb2e80.mjs.map (8.02 kB) (1.97 kB gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-404-styles.1e0dde27.mjs (3.98 kB) (1.25 kB gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-404-styles.1e0dde27.mjs.map (346 B) (215 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-500-4bed7d81.mjs (3.07 kB) (1.35 kB gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-500-4bed7d81.mjs.map (1.68 kB) (600 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-500-styles.cf4b3e80.mjs (2.28 kB) (870 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/error-500-styles.cf4b3e80.mjs.map (346 B) (217 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/island-renderer-9ab8e6f6.mjs (1.17 kB) (526 B gzip)
  β”œβ”€ .output/server/chunks/app/_nuxt/island-renderer-9ab8e6f6.mjs.map (897 B) (414 B gzip)
  β”œβ”€ .output/server/chunks/app/client.manifest.mjs (2.52 kB) (461 B gzip)
  β”œβ”€ .output/server/chunks/app/client.manifest.mjs.map (2.04 kB) (405 B gzip)
  β”œβ”€ .output/server/chunks/app/server.mjs (123 kB) (23.7 kB gzip)
  β”œβ”€ .output/server/chunks/app/server.mjs.map (209 B) (156 B gzip)
  β”œβ”€ .output/server/chunks/app/styles.mjs (533 B) (269 B gzip)
  β”œβ”€ .output/server/chunks/app/styles.mjs.map (429 B) (216 B gzip)
  β”œβ”€ .output/server/chunks/error-500.mjs (4.26 kB) (1.82 kB gzip)
  β”œβ”€ .output/server/chunks/error-500.mjs.map (193 B) (157 B gzip)
  β”œβ”€ .output/server/chunks/handlers/renderer.mjs (12.9 kB) (4.08 kB gzip)
  β”œβ”€ .output/server/chunks/handlers/renderer.mjs.map (424 B) (226 B gzip)
  β”œβ”€ .output/server/chunks/multipart-parser.mjs (5.04 kB) (2.1 kB gzip)
  β”œβ”€ .output/server/chunks/multipart-parser.mjs.map (210 B) (167 B gzip)
  β”œβ”€ .output/server/chunks/nitro/node-server.mjs (260 kB) (66.6 kB gzip)
  β”œβ”€ .output/server/chunks/nitro/node-server.mjs.map (3.21 kB) (834 B gzip)
  β”œβ”€ .output/server/chunks/rollup/_virtual_spa-template.mjs (94 B) (100 B gzip)
  β”œβ”€ .output/server/chunks/rollup/_virtual_spa-template.mjs.map (112 B) (112 B gzip)
  β”œβ”€ .output/server/chunks/test.mjs (492 B) (250 B gzip)
  β”œβ”€ .output/server/chunks/test.mjs.map (263 B) (163 B gzip)
  β”œβ”€ .output/server/index.mjs (389 B) (210 B gzip)
  └─ .output/server/package.json (708 B) (294 B gzip)
Ξ£ Total size: 2.33 MB (558 kB gzip)
βœ” You can preview this build using node .output/server/index.mjs                                                 nitro 11:51:05
✨  Done in 14.51s.

@danielroe
Copy link
Member Author

Reopened to investigate.

@fabianwohlfart
Copy link

So for now we can fix it with manually importing it.
Would be great to resolve the autoimport in the future.

import { useNitroApp } from '#internal/nitro/app'

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

Successfully merging this pull request may close these issues.

None yet

3 participants