"Unknown file extension" error with Nuxtjs/google-fonts package

153 views Asked by At

Following the docs, I installed the package through npm install -D @nuxtjs/google-fonts (since I'm using Nuxt v2.14.7) then added '@nuxtjs/google-fonts' to my buildModules array in nuxt.config.js.

Just by doing that, I immediately get this error:

FATAL Unknown file extension: D:\projects...\node_modules\pathe\dist\index.cjs

Error [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension: node_modules\pathe\dist\index.cjs at /D:/projects/.../node_modules/@nuxtjs/google-fonts/dist/module.mjs:1 at Generator.next ()

Any idea what's wrong here?

3

There are 3 answers

1
Andri Nugroho On
  1. Delete node_modules folder,
  2. Delete package.lock.json,
  3. Clean up the NPM cache by running npm cache clean --force,
  4. Finally , you can try to npm install

if this not work, try to remove @nuxtjs/google-fonts with npm remove @nuxtjs/google-fonts and reinstall it npm install -D @nuxtjs/google-fonts

I hope this work

2
Ediz Suleyman On

You might need to check your configurations and the way you import with modules based on whether you use CommonJS module or ES module.

// For CommonJS module:
const pathe = require('pathe');

// For ES module:
import * as pathe from 'pathe';

And if you are using ES module, in package.json make sure to add this code section:

{
  "type": "module"
}

Hopefully this will resolve your issue.

1
B_Cbk On

Here are a few potential solutions for this problem:

  1. Downgrade your Node.js version: Downgrading your Node.js version to 19.8.1 or earlier may solve this issue. You can use Node Version Manager (nvm) to easily switch between Node.js versions.(this procedure usually eliminates the problem.)
  2. Clear the npm cache: Sometimes the npm cache can cause issues. Clear the cache by running npm cache clean --force
  3. Delete node_modules and package-lock.json: You can try deleting the node_modules folder and package-lock.json, then run npm install again.
  4. Use Yarn instead of npm: Yarn is an alternative package manager that can sometimes handle dependencies better than npm.

Here's an example of downgrading your Node.js version using nvm:

nvm install 19.8.1 nvm use 19.8.1

How to clean the npm cache: npm cache clean --force