Search code examples
typescriptvue.jsnuxt.jstsconfignuxt3.js

Cannot find module - Nuxt 3, TypeScript


When trying to do an import .ts file in 'nuxt.config.ts' using the path '@/' and '~/' I get the error: Cannot find module '~/path', Require stack: - nuxt.config.ts at Module._resolveFilename....

Sample code in the nuxt.config.ts file

// this code does not work
import headConfig from '~/config/head/headConfig';
// import headConfig from '@/config/head/headConfig';

// this code work
// import headConfig from './config/head/headConfig';


export default defineNuxtConfig({
  devtools: { enabled: false },

  app: {
    head: headConfig,
  },
});

Demo on the stackblitz

Nuxt 3.8.2 | node 18.18.0 | npm 9.4.2


Solution

  • That feature is currently not supported. So, inside the nuxt.config.ts file, you have to use relative or absolute paths for import.