[Vuejs]-TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json"

4👍

i was with the same error when trying to import a json for my server.

needs an import assertion of type "json"

I resolve with this:

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

const exemple = require('./data/exemple.json');

Use this with your json.file and the node will reconize the importation.

Another exemple:

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const swaggerDocs = require("./swagger.json");

Leave a comment