My top-level package.json
defines 3 workspaces which are located in the same git repo:
"workspaces": [
"src/infrastructure",
"src/core",
"src/webapi"
]
Symbols are exported in the index.ts
from each of the workspaces. All of them use NodeNext
module type. When I try to import the symbols in one of the workspaces – webapi
, it hits the following error:
Exception during run: file:///usr/src/Node.JSRestAPI/src/webapi/routes/api.ts:13
import { StudentRepository, TeacherRepository, LoggerImpl, DatabaseTypes, Database } from "infrastructure";
^^^^^^^^
SyntaxError: Named export 'Database' not found. The requested module 'infrastructure' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'infrastructure';
const { StudentRepository, TeacherRepository, LoggerImpl, DatabaseTypes, Database } = pkg;
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 ModuleLoader.import (node:internal/modules/esm/loader:475:24)
at async formattedImport (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:9:14)
at async Object.exports.requireOrImport (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:42:28)
at async Object.exports.loadFilesAsync (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
at async singleRun (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/cli/run-helpers.js:158:3)
at async Object.exports.handler (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/cli/run.js:370:5)