N
Nuxt3mo ago
Viridian

Strange error when trying to run dev mode on a fresh install

For some reason, I seem to be getting this error when trying to run dev mode on my fresh Nuxt installation. I only installed nuxthub:
ERROR The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer' 17:35:40

import { createNuxtDevServer } from './dev2.mjs';
^^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:254:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
at async runCommand$1 (/C:/Users/Moos/Documents/GitHub/portfolio/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.f8a4d1b7.mjs:1637:28)
at async runMain$1 (/C:/Users/Moos/Documents/GitHub/portfolio/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.f8a4d1b7.mjs:1777:7)



ERROR The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer'
ERROR The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer' 17:35:40

import { createNuxtDevServer } from './dev2.mjs';
^^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:254:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
at async runCommand$1 (/C:/Users/Moos/Documents/GitHub/portfolio/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.f8a4d1b7.mjs:1637:28)
at async runMain$1 (/C:/Users/Moos/Documents/GitHub/portfolio/node_modules/.pnpm/[email protected]/node_modules/nuxi/dist/shared/nuxi.f8a4d1b7.mjs:1777:7)



ERROR The requested module './dev2.mjs' does not provide an export named 'createNuxtDevServer'
Any idea what is going wrong here? It seems strange.
11 Replies
kapa.ai
kapa.ai3mo ago
Hi @Viridian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This error suggests there might be an issue with your Nuxt installation or configuration. Based on the knowledge sources provided, I can offer some insights and potential solutions: 1. The error indicates that the module './dev2.mjs' doesn't export 'createNuxtDevServer', which is unexpected for a fresh Nuxt installation. This could be due to a few reasons: 2. Incompatible versions: Make sure you're using compatible versions of Nuxt and its dependencies. The error message mentions [email protected], which is a recent version. Ensure all your packages are up to date. 3. Incomplete or corrupted installation: Try removing the node_modules folder and package-lock.json (or yarn.lock if using Yarn), then reinstall your dependencies. 4. ESM-related issues: Nuxt 3 uses ES Modules, which can sometimes cause issues. As mentioned in the ES Modules troubleshooting guide (https://nuxt.com/docs/guide/concepts/esm#troubleshooting-esm-issues), you might need to transpile certain libraries or alias them to their CommonJS versions if they're not properly supporting ESM. 5. Node.js version: Ensure you're using a compatible Node.js version. Nuxt 3 requires Node.js 14.16.0 or later, preferably the latest LTS version. To troubleshoot this issue, you can try the following steps: 1. Delete the .nuxt, node_modules, and .output directories, as well as the package-lock.json or yarn.lock file. 2. Ensure you're using the latest LTS version of Node.js. 3. Reinstall your dependencies with npm install or yarn install. 4. Try running the development server again with npm run dev or yarn dev. If the issue persists, you might want to check if there are any known issues with the nuxthub package you installed. It's possible that this package is causing conflicts with the core Nuxt functionality. If none of these steps resolve the issue, you may want to create a minimal reproduction of the problem and report it as a bug to the Nuxt GitHub repository (https://nuxt.com/docs/community/reporting-bugs#figure-out-what-the-cause-might-be). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the code you've provided and the information from the knowledge sources, I can see that you're using useFetch within a composable function. This approach can lead to issues with data fetching, as explained in the Nuxt 3 documentation. The main problem is that useFetch is designed to be used directly in the setup function of a component, plugin, or route middleware. When you use it inside a custom composable like createPokemonLabels, it may not behave as expected. To fix this issue, you have a few options: 1. Move the useFetch call directly into your component's setup function:
<script setup lang="ts">
import { useInputLabels } from '~~/composables/UseInputLabels'

// ... other imports and type definitions ...

const { data: pokemonData, error: pokemonError } = await useFetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')

const { items, isLoading } = useInputLabels(pokemonData.value?.data || [])

// ... rest of your component logic ...
</script>
<script setup lang="ts">
import { useInputLabels } from '~~/composables/UseInputLabels'

// ... other imports and type definitions ...

const { data: pokemonData, error: pokemonError } = await useFetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')

const { items, isLoading } = useInputLabels(pokemonData.value?.data || [])

// ... rest of your component logic ...
</script>
2. Use $fetch instead of useFetch in your composable:
async function createPokemonLabels(): Promise<InputMenuItem[]> {
try {
const response = await $fetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')
if (response.success) {
return response.data.map(pokemon => ({
type: 'pokemon',
label: pokemon.name,
}))
}
console.error('Invalid pokedex data format', response)
return []
} catch (error) {
console.error('Failed to load pokedex data:', error)
return []
}
}
async function createPokemonLabels(): Promise<InputMenuItem[]> {
try {
const response = await $fetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')
if (response.success) {
return response.data.map(pokemon => ({
type: 'pokemon',
label: pokemon.name,
}))
}
console.error('Invalid pokedex data format', response)
return []
} catch (error) {
console.error('Failed to load pokedex data:', error)
return []
}
}
3. If you need to keep the composable structure, you can pass a fetcher function to your composable:
export function useInputLabels(fetchPokemon: () => Promise<PokemonSchema[]>) {
const items = ref<InputMenuItem[]>([])
const isLoading = ref(true)

async function loadItems() {
try {
const [routes, trainers, pokemonData] = await Promise.all([
createRouteLabels(),
createTrainerLabels(),
fetchPokemon(),
])
const pokemonLabels = pokemonData.map(pokemon => ({
type: 'pokemon' as const,
label: pokemon.name,
}))
// ... rest of your logic ...
}
finally {
isLoading.value = false
}
}

onMounted(() => loadItems())

return { items, isLoading }
}
export function useInputLabels(fetchPokemon: () => Promise<PokemonSchema[]>) {
const items = ref<InputMenuItem[]>([])
const isLoading = ref(true)

async function loadItems() {
try {
const [routes, trainers, pokemonData] = await Promise.all([
createRouteLabels(),
createTrainerLabels(),
fetchPokemon(),
])
const pokemonLabels = pokemonData.map(pokemon => ({
type: 'pokemon' as const,
label: pokemon.name,
}))
// ... rest of your logic ...
}
finally {
isLoading.value = false
}
}

onMounted(() => loadItems())

return { items, isLoading }
}
Then in your component:
<script setup lang="ts">
import { useInputLabels } from '~~/composables/UseInputLabels'

const fetchPokemon = async () => {
const { data } = await useFetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')
return data.value?.success ? data.value.data : []
}

const { items, isLoading } = useInputLabels(fetchPokemon)

// ... rest of your component logic ...
</script>
<script setup lang="ts">
import { useInputLabels } from '~~/composables/UseInputLabels'

const fetchPokemon = async () => {
const { data } = await useFetch<{ success: boolean, data: PokemonSchema[] }>('/api/parse/pokedex')
return data.value?.success ? data.value.data : []
}

const { items, isLoading } = useInputLabels(fetchPokemon)

// ... rest of your component logic ...
</script>
These approaches should help resolve the issue with data fetching in your composable. Remember, as stated in the Nuxt documentation, useFetch and useAsyncData are designed to work directly in component setup functions, plugins, or route middleware to ensure proper server-side rendering and client-side hydration. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To capture the value of the selected item in a UInputMenu component whenever it's clicked, you can use the v-model directive along with a watcher or a computed property. Here's how you can do it based on the information from the Nuxt UI documentation: 1. First, set up your UInputMenu with a v-model:
<template>
<UInputMenu
v-model="selected"
:options="options"
placeholder="Select an option"
/>
</template>

<script setup>
import { ref, watch } from 'vue'

const options = ['Option 1', 'Option 2', 'Option 3']
const selected = ref(null)

watch(selected, (newValue) => {
console.log('Selected item:', newValue)
// Perform any action you want with the selected value
})
</script>
<template>
<UInputMenu
v-model="selected"
:options="options"
placeholder="Select an option"
/>
</template>

<script setup>
import { ref, watch } from 'vue'

const options = ['Option 1', 'Option 2', 'Option 3']
const selected = ref(null)

watch(selected, (newValue) => {
console.log('Selected item:', newValue)
// Perform any action you want with the selected value
})
</script>
In this example, the selected ref will automatically update whenever an item is selected in the UInputMenu. The watcher will then log the new value and allow you to perform any desired actions. If you're using objects as options, you can specify which attribute to use as the label and value:
<template>
<UInputMenu
v-model="selected"
:options="options"
option-attribute="name"
value-attribute="id"
placeholder="Select a person"
/>
</template>

<script setup>
import { ref, watch } from 'vue'

const options = [
{ id: 1, name: 'Wade Cooper' },
{ id: 2, name: 'Arlene Mccoy' },
{ id: 3, name: 'Devon Webb' }
]
const selected = ref(null)

watch(selected, (newValue) => {
console.log('Selected person ID:', newValue)
// Perform any action you want with the selected ID
})
</script>
<template>
<UInputMenu
v-model="selected"
:options="options"
option-attribute="name"
value-attribute="id"
placeholder="Select a person"
/>
</template>

<script setup>
import { ref, watch } from 'vue'

const options = [
{ id: 1, name: 'Wade Cooper' },
{ id: 2, name: 'Arlene Mccoy' },
{ id: 3, name: 'Devon Webb' }
]
const selected = ref(null)

watch(selected, (newValue) => {
console.log('Selected person ID:', newValue)
// Perform any action you want with the selected ID
})
</script>
In this case, the selected value will be the id of the selected person. You can also use the @update:model-value event if you prefer an event-based approach:
<template>
<UInputMenu
v-model="selected"
:options="options"
placeholder="Select an option"
@update:model-value="handleSelection"
/>
</template>

<script setup>
import { ref } from 'vue'

const options = ['Option 1', 'Option 2', 'Option 3']
const selected = ref(null)

const handleSelection = (value) => {
console.log('Selected item:', value)
// Perform any action you want with the selected value
}
</script>
<template>
<UInputMenu
v-model="selected"
:options="options"
placeholder="Select an option"
@update:model-value="handleSelection"
/>
</template>

<script setup>
import { ref } from 'vue'

const options = ['Option 1', 'Option 2', 'Option 3']
const selected = ref(null)

const handleSelection = (value) => {
console.log('Selected item:', value)
// Perform any action you want with the selected value
}
</script>
This approach allows you to handle the selection in a separate function, which can be useful for more complex logic. These examples are based on the usage information provided in the Nuxt UI documentation for the InputMenu component. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the information provided in the knowledge sources and your current setup, I can explain why you're experiencing this issue with page transitions and suggest a solution. The problem you're encountering is likely related to the way Nuxt handles page transitions when navigating between pages. According to the Nuxt documentation on transitions, there are a few key points to consider: 1. Your current setup in app.vue is correct for defining global page transitions. 2. However, when you have nested routes or are changing layouts as well as pages, the global page transition might not run as expected. To solve this issue and ensure consistent transitions between all your pages, including from index.vue to [id].vue, you can try the following approaches: 1. Use definePageMeta in both of your pages to explicitly set the transition: In pages/index.vue and pages/pokemon/[id].vue, add the following:
<script setup>
definePageMeta({
pageTransition: {
name: 'page',
mode: 'out-in'
}
})
</script>
<script setup>
definePageMeta({
pageTransition: {
name: 'page',
mode: 'out-in'
}
})
</script>
2. Alternatively, you can set the default transition in your nuxt.config.ts file:
export default defineNuxtConfig({
app: {
pageTransition: { name: 'page', mode: 'out-in' }
},
})
export default defineNuxtConfig({
app: {
pageTransition: { name: 'page', mode: 'out-in' }
},
})
3. If you're using layouts, make sure both pages are using the same layout, or consider using a layout transition instead. 4. Ensure that your [id].vue page has a single root element. As mentioned in a GitHub issue, pages must have a single root element for transitions to work correctly. If these solutions don't resolve the issue, you might want to check if there are any other factors interfering with the transition, such as: - Differences in the DOM structure between the two pages - Any middleware or navigation guards that might be affecting the transition - Ensure that both pages are fully loaded before the transition occurs Remember, as stated in the Nuxt documentation, "If you are changing layouts as well as page, the page transition you set here will not run. Instead, you should set a layout transition." If you continue to experience issues after trying these solutions, you may want to create a minimal reproduction of the problem and seek further assistance from the Nuxt community or report it as a potential bug. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Viridian
ViridianOP3w ago
@kapa.ai how can I set a custom color (e.g. a tailwind class red-100) for my UProgress element? I can only use predefined ones like 'primary' for now
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To set a custom color for your UProgress element using a Tailwind class like 'red-100', you'll need to modify the component's configuration. The Nuxt UI library allows for customization of components through the app.config.ts file or the ui prop. Here's how you can achieve this: 1. Using app.config.ts: Create or modify your app.config.ts file in the root of your Nuxt project:
export default defineAppConfig({
ui: {
progress: {
color: {
custom: {
solid: 'bg-red-100'
}
}
}
}
})
export default defineAppConfig({
ui: {
progress: {
color: {
custom: {
solid: 'bg-red-100'
}
}
}
}
})
Then, in your component:
<template>
<UProgress color="custom" />
</template>
<template>
<UProgress color="custom" />
</template>
2. Using the ui prop: You can directly pass the custom color configuration to the UProgress component:
<template>
<UProgress :ui="{ color: { custom: { solid: 'bg-red-100' } } }" color="custom" />
</template>
<template>
<UProgress :ui="{ color: { custom: { solid: 'bg-red-100' } } }" color="custom" />
</template>
3. Extending the default configuration: If you want to keep the existing color options and add your custom color, you can extend the default configuration:
export default defineAppConfig({
ui: {
progress: {
color: {
red: {
solid: 'bg-red-100'
}
}
}
}
})
export default defineAppConfig({
ui: {
progress: {
color: {
red: {
solid: 'bg-red-100'
}
}
}
}
})
Then use it in your component:
<template>
<UProgress color="red" />
</template>
<template>
<UProgress color="red" />
</template>
These approaches are based on the theming capabilities of Nuxt UI as described in the Theming documentation. Remember that when using custom Tailwind classes, you might need to safelist them to prevent purging in production builds. You can do this in your nuxt.config.ts:
export default defineNuxtConfig({
ui: {
safelistColors: ['red']
}
})
export default defineNuxtConfig({
ui: {
safelistColors: ['red']
}
})
This information is derived from the Nuxt UI documentation on safelisting colors. By following these steps, you should be able to use custom Tailwind classes like 'red-100' for your UProgress element. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?