N
Nuxt4mo ago
WiFi Plug

trying to use the world-countries package but i get this error

"import countries from 'world-countries'" this is my import this is the error "Module "file:///C:/Users/user/Desktop/nuxt/node_modules/.pnpm/world-countries@5.1.0/node_modules/world-countries/countries.json" needs an import attribute of "type: json"" why is this and how do i solve it
26 Replies
kapa.ai
kapa.ai4mo ago
Hi @WiFi Plug. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error you're seeing:
Module "file:///.../world-countries/countries.json" needs an import attribute of "type: json"
Module "file:///.../world-countries/countries.json" needs an import attribute of "type: json"
happens because, in ESM (ECMAScript Modules) environments like Nuxt 3 (with "type": "module" in your package.json), importing JSON files directly using import countries from 'world-countries' requires you to specify the import attribute assert { type: "json" }. This is a Node.js and Vite (the default Nuxt 3 bundler) requirement for ESM compatibility. How to fix: Update your import statement to:
import countries from 'world-countries/countries.json' assert { type: "json" }
import countries from 'world-countries/countries.json' assert { type: "json" }
If you are using TypeScript, you may also need to add a type declaration for importing JSON files, for example in a types.d.ts file:
declare module "*.json" {
const value: any;
export default value;
}
declare module "*.json" {
const value: any;
export default value;
}
Why does this happen? - In ESM, importing JSON requires the assert { type: "json" } syntax for security and clarity. - Nuxt 3 projects with "type": "module" in package.json are true ESM environments, so this rule applies. - Some packages (like world-countries) export their data as JSON, so you must use the correct import syntax. References: - This is a common ESM issue, as described in the Nuxt docs about ESM compatibility and file imports Library Author Guide. - Errors like "Unexpected character" or "needs an import attribute" are typical when importing non-JS files without the correct import assertion, as seen in related issues and error reports Stack Overflow example. If you continue to have issues, make sure your Vite and Nuxt versions are up to date, as some older versions may not handle JSON imports as expected. If you are using a custom Vite config, ensure the vite:json plugin is enabled. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai im using typescript where should i put that type declaration? in the same file or in the shared/types folder? then import it were i use countries?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- In a Nuxt 3 project using TypeScript, the recommended place to put global type declarations (like for importing JSON files) is in a dedicated types declaration file, typically inside a types directory at the project root (e.g., ~/types). You do not need to import this declaration anywhere—TypeScript will pick it up automatically if the file ends with .d.ts and is included in your tsconfig.json (which is the default behavior in Nuxt) How to Automatically Recognize Type Definitions in Nuxt.js Project Without Explicit Imports in VSCode?. For example, create a file called types/json.d.ts at your project root with the following content:
// ~/types/json.d.ts
declare module "*.json" {
const value: any;
export default value;
}
// ~/types/json.d.ts
declare module "*.json" {
const value: any;
export default value;
}
You do not need to import this type declaration where you use countries; TypeScript will recognize it globally. You can also use the shared/types folder introduced in Nuxt 3.14+ for type declarations, and these will be auto-imported if you have opted into Nuxt 4 compatibility by setting future.compatibilityVersion: 4 in your nuxt.config.ts. Otherwise, placing your .d.ts file in ~/types is the standard approach and works out of the box shared directory docs. So, the best practice is to put your type declaration in ~/types/json.d.ts. No need to import it manually—TypeScript will handle it for you. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai i have pinia store, I want to grab the cloudflare detected country 2 letter code when the store renders on ssr how do i cleanly do it
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To grab the Cloudflare-detected country code on SSR and make it available in your Pinia store in a Nuxt 3 app, you need to: 1. Read the country code from the Cloudflare-provided request headers (e.g., cf-ipcountry) during SSR. 2. Set this value in your Pinia store during the server-side rendering phase, so it's available to your app. A clean approach is to use a Nuxt plugin that runs on the server, reads the header, and updates your Pinia store accordingly. Here’s how you can do it: --- 1. Create a Pinia store (e.g., stores/geo.ts):
import { defineStore } from 'pinia'

export const useGeoStore = defineStore('geo', {
state: () => ({
countryCode: ''
}),
actions: {
setCountryCode(code: string) {
this.countryCode = code
}
}
})
import { defineStore } from 'pinia'

export const useGeoStore = defineStore('geo', {
state: () => ({
countryCode: ''
}),
actions: {
setCountryCode(code: string) {
this.countryCode = code
}
}
})
--- 2. Create a Nuxt plugin (e.g., plugins/init-geo.ts):
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useGeoStore } from '~/stores/geo'

export default defineNuxtPlugin(() => {
// Only runs on server during SSR
if (process.server) {
const headers = useRequestHeaders()
const countryCode = headers['cf-ipcountry'] || ''
const geoStore = useGeoStore()
geoStore.setCountryCode(countryCode)
}
})
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useGeoStore } from '~/stores/geo'

export default defineNuxtPlugin(() => {
// Only runs on server during SSR
if (process.server) {
const headers = useRequestHeaders()
const countryCode = headers['cf-ipcountry'] || ''
const geoStore = useGeoStore()
geoStore.setCountryCode(countryCode)
}
})
--- How it works: - On SSR, Cloudflare injects the cf-ipcountry header into the request. - The Nuxt plugin reads this header and sets it in the Pinia store. - Your components can then access geoStore.countryCode as needed. --- Note:
This approach is similar to how you would inject server-evaluated variables into a Pinia store using a Nuxt plugin, as shown in this example for IP detection (replace the IP logic with country code logic):
Create a plugin in your /plugins (something may be like init.ts)
import { defineNuxtPlugin } from '#app';
import { useIpStore } from '~/stores/ip';

export default defineNuxtPlugin(async (nuxtApp) => {
const headers = useRequestHeaders();
const ip = headers['x-real-ip'] ?? '';
const ipStore = useIpStore();
ipStore.setIp(ip);
});
import { defineNuxtPlugin } from '#app';
import { useIpStore } from '~/stores/ip';

export default defineNuxtPlugin(async (nuxtApp) => {
const headers = useRequestHeaders();
const ip = headers['x-real-ip'] ?? '';
const ipStore = useIpStore();
ipStore.setIp(ip);
});
Nuxt3: provide server evaluated variable to client at every request
Just adapt the header and store for your use case. --- If you need to support client-side navigation as well, you may want to add fallback logic, but for SSR and initial page load, this method is clean and effective. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai
export const useCurrencyStore = defineStore(
'currency',
() => {
// Get country from SSR context (Cloudflare headers)
const ssrCountry = null
// Only runs on server during SSR
if (import.meta.server) {
const headers = useRequestHeaders()
ssrCountry = headers['cf-ipcountry'] as string
}
export const useCurrencyStore = defineStore(
'currency',
() => {
// Get country from SSR context (Cloudflare headers)
const ssrCountry = null
// Only runs on server during SSR
if (import.meta.server) {
const headers = useRequestHeaders()
ssrCountry = headers['cf-ipcountry'] as string
}
how about like this how do i fix this part
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Your approach is close, but there are a couple of issues: 1. You cannot assign to a const variable (ssrCountry) after declaration.
2. Pinia's defineStore setup function runs on both server and client, but you should avoid using composables like useRequestHeaders() directly inside the store's setup function because composables are meant to be used inside components or plugins, not directly in the store definition. The recommended pattern, as shown in the knowledge sources, is to use a Nuxt plugin to read the header and set the value in the store during SSR. This is demonstrated in the answer for injecting server-evaluated variables into a Pinia store using a plugin, not directly in the store definition itself Nuxt3: provide server evaluated variable to client at every request. Example using a plugin: 1. Pinia store (stores/currency.ts):
import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', {
state: () => ({
country: ''
}),
actions: {
setCountry(country: string) {
this.country = country
}
}
})

import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', {
state: () => ({
country: ''
}),
actions: {
setCountry(country: string) {
this.country = country
}
}
})

2. Nuxt plugin (plugins/init-currency.ts):
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || ''
const currencyStore = useCurrencyStore()
currencyStore.setCountry(country)
}
})

import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || ''
const currencyStore = useCurrencyStore()
currencyStore.setCountry(country)
}
})

Summary:
- Do not use useRequestHeaders() directly in the Pinia store definition. - Use a Nuxt plugin to read the header and set the value in the store during SSR, as shown in the knowledge sources. This approach is clean, SSR-friendly, and aligns with Nuxt and Pinia best practices Nuxt3: provide server evaluated variable to client at every request. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai
export const useCurrencyStore = defineStore(
'currency',
() => {
// State
const preferredCurrency = ref<CurrencyDisplay>('coins')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)

// Get country from SSR context (Cloudflare headers)
if (import.meta.server) {
const headers = useRequestHeaders()
detectedCountry.value = (headers['cf-ipcountry'] as string) || null
// temporary testing manual override
detectedCountry.value = 'GBdfhd'
console.log('🌍 SSR Country Detection:', detectedCountry.value || 'No country detected')
}
export const useCurrencyStore = defineStore(
'currency',
() => {
// State
const preferredCurrency = ref<CurrencyDisplay>('coins')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)

// Get country from SSR context (Cloudflare headers)
if (import.meta.server) {
const headers = useRequestHeaders()
detectedCountry.value = (headers['cf-ipcountry'] as string) || null
// temporary testing manual override
detectedCountry.value = 'GBdfhd'
console.log('🌍 SSR Country Detection:', detectedCountry.value || 'No country detected')
}
so when testing this it pritns during ssr the detectedcountry but during client side execution the value is lost how do i ensure the value for detectedcountry isn't lost once the client is running it
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The issue you're experiencing is due to how SSR (Server-Side Rendering) and hydration work in Nuxt 3. When you set detectedCountry.value during SSR, that value exists only on the server-rendered instance. By default, local state (like a ref in a Pinia store) is not automatically serialized and sent to the client unless you use an SSR-friendly mechanism. To persist state from SSR to the client, you should use Nuxt's SSR-friendly state management, such as the useState composable, or ensure your store is initialized with data that is serialized and hydrated on the client. However, Pinia stores do not automatically serialize state set during SSR unless you use a plugin or a composable that handles this. Recommended Solution:
Use a Nuxt plugin to set the value in your Pinia store during SSR. This ensures the value is included in the Nuxt payload and hydrated on the client, as shown in the knowledge sources:
Create a plugin in your /plugins (something may be like init.ts)
import { defineNuxtPlugin } from '#app';
import { useIpStore } from '~/stores/ip';

export default defineNuxtPlugin(async (nuxtApp) => {
const headers = useRequestHeaders();
const ip = headers['x-real-ip'] ?? '';
const ipStore = useIpStore();
ipStore.setIp(ip);
});
import { defineNuxtPlugin } from '#app';
import { useIpStore } from '~/stores/ip';

export default defineNuxtPlugin(async (nuxtApp) => {
const headers = useRequestHeaders();
const ip = headers['x-real-ip'] ?? '';
const ipStore = useIpStore();
ipStore.setIp(ip);
});
Nuxt3: provide server evaluated variable to client at every request
How to adapt this for your use case: 1. Pinia Store (stores/currency.ts):
import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', {
state: () => ({
detectedCountry: null as string | null
}),
actions: {
setDetectedCountry(country: string | null) {
this.detectedCountry = country
}
}
})

import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', {
state: () => ({
detectedCountry: null as string | null
}),
actions: {
setDetectedCountry(country: string | null) {
this.detectedCountry = country
}
}
})

2. Nuxt Plugin (plugins/init-currency.ts):
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || null
const currencyStore = useCurrencyStore()
currencyStore.setDetectedCountry(country)
}
})

import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || null
const currencyStore = useCurrencyStore()
currencyStore.setDetectedCountry(country)
}
})

This way, the value is set during SSR and will be available on the client after hydration, solving the problem of the value being lost. Summary:
- Do not set SSR-only state directly in the store's setup function. - Use a Nuxt plugin to set the value during SSR, so it is serialized and hydrated on the client Nuxt3: provide server evaluated variable to client at every request. If you need even more control over hydration, you can look into advanced composables like useHydration, but for most use cases, the plugin approach is clean and effective. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai okay so if i make a plugin that runs during ssr to set this value that's fine but how do i keep my pinia store mostly normal as i have more stuff inside it too
export const useCurrencyStore = defineStore(
'currency',
() => {
// State
const preferredCurrency = ref<CurrencyDisplay>('default')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)
export const useCurrencyStore = defineStore(
'currency',
() => {
// State
const preferredCurrency = ref<CurrencyDisplay>('default')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You can absolutely keep your Pinia store "normal" and include as much state and logic as you need. The key is to set the SSR-derived value (like detectedCountry) from a Nuxt plugin during SSR, rather than trying to initialize it directly in the store's setup function. This approach is shown in the knowledge sources and is the recommended pattern for injecting server-derived values into a Pinia store in Nuxt 3 Nuxt3: provide server evaluated variable to client at every request. Your store can look like this:
// stores/currency.ts
import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', () => {
const preferredCurrency = ref<CurrencyDisplay>('default')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)

function setDetectedCountry(country: string | null) {
detectedCountry.value = country
hasDetectedLocation.value = !!country
}

// ...other actions, getters, etc.

return {
preferredCurrency,
exchangeRates,
hasDetectedLocation,
detectedCountry,
setDetectedCountry,
// ...other state and actions
}
})
// stores/currency.ts
import { defineStore } from 'pinia'

export const useCurrencyStore = defineStore('currency', () => {
const preferredCurrency = ref<CurrencyDisplay>('default')
const exchangeRates = ref<ExchangeRates>({})
const hasDetectedLocation = ref<boolean>(false)
const detectedCountry = ref<string | null>(null)

function setDetectedCountry(country: string | null) {
detectedCountry.value = country
hasDetectedLocation.value = !!country
}

// ...other actions, getters, etc.

return {
preferredCurrency,
exchangeRates,
hasDetectedLocation,
detectedCountry,
setDetectedCountry,
// ...other state and actions
}
})
Then, in your plugin (e.g., plugins/init-currency.ts):
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || null
const currencyStore = useCurrencyStore()
currencyStore.setDetectedCountry(country)
}
})
import { defineNuxtPlugin, useRequestHeaders } from '#app'
import { useCurrencyStore } from '~/stores/currency'

export default defineNuxtPlugin(() => {
if (import.meta.server) {
const headers = useRequestHeaders()
const country = headers['cf-ipcountry'] || null
const currencyStore = useCurrencyStore()
currencyStore.setDetectedCountry(country)
}
})
This way, your store remains clean and "normal," and you only inject the SSR-specific value via the plugin. All other state and logic in your store are unaffected and work as usual. This pattern is directly supported and recommended in the Nuxt documentation and community examples for handling SSR-injected state with Pinia stores in Nuxt 3 Nuxt3: provide server evaluated variable to client at every request. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai so again how can i get around this issue importing this library "import countries from 'world-countries'" "/Desktop/nuxt/node_modules/.pnpm/world-countries@5.1.0/node_modules/world-countries/countries.json" needs an import attribute of "type: json""
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error you are seeing:
Module ".../world-countries/countries.json" needs an import attribute of "type: json"
Module ".../world-countries/countries.json" needs an import attribute of "type: json"
occurs because, in ESM environments (like Nuxt 3 with "type": "module" in your package.json), importing JSON files requires the use of an import assertion. The standard import:
import countries from 'world-countries'
import countries from 'world-countries'
will not work unless the package provides a JS export. Since world-countries exports a JSON file, you need to import it with an assertion:
import countries from 'world-countries/countries.json' assert { type: "json" }
import countries from 'world-countries/countries.json' assert { type: "json" }
This is a requirement of ESM in Node.js and Vite, as described in the Nuxt documentation on ESM compatibility and troubleshooting. If you do not use the assertion, you will get the error you described. This is not a Nuxt-specific issue, but a general ESM/Node.js rule for importing JSON files Troubleshooting ESM Issues. Summary:
- Use the import assertion when importing JSON:
import countries from 'world-countries/countries.json' assert { type: "json" }

import countries from 'world-countries/countries.json' assert { type: "json" }

- This is required in ESM environments, including Nuxt 3. If you need to support older syntax or run into further issues, you may need to check if the library provides a JS export, or use a workaround such as importing and re-exporting the JSON in a JS file, but the knowledge sources do not provide details on that. The main solution is to use the import assertion as shown above. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai "[vite-node] [PARSE_ERROR] C:/Users/user/Desktop/nuxt/shared/utils/countryDetection.ts:3:8 <br><pre>1 | import countries from "world-countries" 2 | import { findCurrencyByCode } from "/@fs/C:/Users/user/Desktop/nuxt/shared/utils/currency.ts"; 3 | assert { type: "json" }; | ^ 4 | export function detectCurrencyFromCountry(countryCode) { 5 | try {</pre><br> [vite-node] [PARSE_ERROR] C:/Users/user/Desktop/nuxt/shared/utils/countryDetection.ts:3:8 <br><pre>1 | import countries from "world-countries" 2 | import { findCurrencyByCode } from "/@fs/C:/Users/user/Desktop/nuxt/shared/utils/currency.ts"; 3 | assert { type: "json" }; | ^ 4 | export function detectCurrencyFromCountry(countryCode) { 5 | try {</pre><br> at C:/Users/user/Desktop/nuxt/shared/utils/countryDetection.ts:3:8)'
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error you are seeing:
[vite-node] [PARSE_ERROR] ...countryDetection.ts:3:8
1 | import countries from "world-countries"
...
3 | assert { type: "json" };
[vite-node] [PARSE_ERROR] ...countryDetection.ts:3:8
1 | import countries from "world-countries"
...
3 | assert { type: "json" };
indicates that you are trying to use the assert { type: "json" } syntax separately from the import statement, which is not valid JavaScript or TypeScript syntax. The assert { type: "json" } must be part of the import statement itself. Correct usage:
import countries from 'world-countries/countries.json' assert { type: "json" }
import countries from 'world-countries/countries.json' assert { type: "json" }
Do not write assert { type: "json" }; on its own line. It must be attached to the import statement. Summary of steps: 1. Import the JSON file directly with the assertion:
import countries from 'world-countries/countries.json' assert { type: "json" }

import countries from 'world-countries/countries.json' assert { type: "json" }

2. Do not use import countries from 'world-countries' (without the .json and assertion) in ESM/TypeScript with Nuxt 3, as this will not work and will cause the error you are seeing. This requirement is due to how ESM handles JSON imports, as described in the Nuxt documentation on ESM compatibility and troubleshooting. If you continue to have issues, ensure your TypeScript configuration allows JSON imports (see previous answers for type declaration tips), and always use the correct import assertion syntax. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai "import("world-countries, { with: { type: "json" } });" can i use this style of import instead as it doesn't seem to return errors at least?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm sorry, but the knowledge sources do not contain explicit information about using the dynamic import syntax with the { with: { type: "json" } } option (i.e., import('world-countries', { with: { type: "json" } })) in Nuxt 3 or Vite environments. The official ESM and Nuxt documentation only reference the static import assertion syntax for JSON files:
import countries from 'world-countries/countries.json' assert { type: "json" }
import countries from 'world-countries/countries.json' assert { type: "json" }
There is no mention of the dynamic import with the { with: { type: "json" } } option in the provided knowledge sources, so I cannot confirm its support or recommend it as a solution based on the available documentation. If it appears to work in your environment, it may be due to recent updates in Vite or Node.js, but this is not documented in the Nuxt knowledge sources provided. If you need a fully supported and documented approach, the static import with assertion is the recommended method according to the Nuxt docs Troubleshooting ESM Issues. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?