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

Nuxt Bridge app.baseURL doesn't work with i18n module #16

Closed
thomas4Bitcraft opened this issue Feb 17, 2022 · 12 comments · Fixed by #830
Closed

Nuxt Bridge app.baseURL doesn't work with i18n module #16

thomas4Bitcraft opened this issue Feb 17, 2022 · 12 comments · Fixed by #830
Labels

Comments

@thomas4Bitcraft
Copy link

thomas4Bitcraft commented Feb 17, 2022

Environment


  • Operating System: Darwin
  • Node Version: v14.18.1
  • Nuxt Version: latest
  • Package Manager: npm@6.14.15
  • Bundler: Webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

nuxt.config.js

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
router: {
    base: '/d/'
  },
})

Describe the bug

The base path in nuxt bridge seems to be broken. If I set it to the above /d/ every preload link in the frontend is set to /d/d/ and all files are also reachable only with this path.

image

image

It seems the only url which is not affected by this is the one to the header js file in production
image

What makes the thing worse - because the file lies under /d/d/ and the whole site is broken

Additional context

No response

Logs

No response

@danielroe danielroe changed the title Nuxt Bridge router basePath is broken Nuxt Bridge router basePath cannot have a trailing slash Feb 17, 2022
@danielroe danielroe added bug Something isn't working and removed pending triage labels Feb 17, 2022
@thomas4Bitcraft
Copy link
Author

thomas4Bitcraft commented Feb 17, 2022

@danielroe I made a mistake at my initial issue: /d is also not working. So the basePath property as a whole seems to be broken right now

@danielroe danielroe added bug Something isn't working question Further information is requested and removed bug Something isn't working labels Feb 17, 2022
@danielroe
Copy link
Member

To configure the base path with Nitro, don't configure router.base directly. Instead, you can pass NUXT_APP_BASE_URL or set app.baseURL.

For example:

yarn build
NUXT_APP_BASE_URL=/d node .output/server/index.mjs

Or:

  import { defineNuxtConfig } from '@nuxt/bridge'
  
  export default defineNuxtConfig({
-   router: {
-     base: '/d/'
-   },
+   app: {
+     baseURL: '/d/'
+   },
  })

Let me know if that resolves it for you.

@danielroe danielroe removed the bug Something isn't working label Feb 17, 2022
@thomas4Bitcraft
Copy link
Author

@danielroe The assets are now resolved and are reachable under /d/. The problem now are the pages or precisely the i18n package.

We have a Cloudfront which routes all /d/ traffic to the lambda where the nuxt application is loaded. But without the router option <domain>/d/en/login is redirected to <domain>/en/login and therefore outside of the application.

@danielroe
Copy link
Member

The router option should be set dynamically based on the basePath. Perhaps you could share some reproduction code? 🙏

@thomas4Bitcraft
Copy link
Author

thomas4Bitcraft commented Feb 17, 2022

Sure I'll create a reproduction. Another thing I noticed:

image

The JS Files in `head` still seems to behave different than all the other nuxt files

@danielroe danielroe changed the title Nuxt Bridge router basePath cannot have a trailing slash Nuxt Bridge app.baseURL doesn't work with i18n module Feb 18, 2022
@danielroe danielroe added bug Something isn't working upstream and removed question Further information is requested labels Feb 18, 2022
@danielroe
Copy link
Member

Would you open an issue on https://github.com/nuxt-community/i18n-module? 🙏

@hughlv
Copy link

hughlv commented Mar 28, 2022

The value of app.baseURL does not apply to ~static, while router.base does.

We were using ~static in img src attribute, e.g. . It works fine during local development, but when we start nuxi build we have to switch from router.base to app.baseURL, which fixes the preload link issue, but created ~static issue again.

For now we have to abandon ~static and replace it with the global var baseURL, not quite elegant anyway.

@danielroe danielroe transferred this issue from nuxt/framework Apr 13, 2022
@sweetpalma
Copy link

sweetpalma commented Aug 12, 2022

I have the exact same issue with a nuxt/bridge even without using any third-party modules. When I define router.base with some value - let's assume /test/ for example - it gets doubled in the script routes embedded to the header. Any solution for this yet?

Снимок экрана 2022-08-12 в 17 34 44

@sweetpalma
Copy link

sweetpalma commented Aug 15, 2022

I was able to hard code _nuxt folder path using buildAssetsDir (it's not even documented!) - but I guess that's a pretty weak solution. Hope this issue will get addressed soon.

Снимок экрана 2022-08-15 в 23 53 50

@emretepedev
Copy link

Same issue here.

@saraha33
Copy link

yes - also had the problem that my fonts in /assets were not found - because the prefix was missing - the key was to specify the buildAssetsDir string as specified by @sweetpalma even though it should be the default anyway...(i also added baseURL and router.base but buildAssetsDir really made all the difference)

app: {
  buildAssetsDir: '/_nuxt/'
}

@ldavisCEI
Copy link

I also had the same issue. I followed the work around by @sweetpalma and @saraha33. That fixed the issue. Thanks!
At least buildAssetsDir is now in the docs.

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

Successfully merging a pull request may close this issue.

7 participants