Код: Выделить всё
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/mrahk/Documents/development/Projects/url-shortner/node_modules/nanoid/index.js from /home/mrahk/Documents/development/Projects/url-shortner/controllers/url.js not supported.
Instead change the require of index.js in /home/mrahk/Documents/development/Projects/url-shortner/controllers/url.js to a dynamic import() which is available in all CommonJS modules.
Код: Выделить всё
url.js
Код: Выделить всё
const asyncHandler = require("express-async-handler");
const urlModel = require("../models/url");
const BASE_URL = process.env.BASE_URL || "http://localhost:8000";
let nanoid;
(async () => {
const { nanoid: nanoidFn } = await import("nanoid");
nanoid = nanoidFn;
})();
Подробнее здесь: https://stackoverflow.com/questions/793 ... -import-fo