bus icon indicating copy to clipboard operation
bus copied to clipboard

Named export <nameExport> not found

Open innovaweb-dev opened this issue 1 year ago • 1 comments

Hello, I tried to learn @node-ts/bus, but I can't import anything. I want just to reproduce this https://bus.node-ts.com/installing/handling-messages

import { Command } from '@node-ts/bus-messages';
SyntaxError: Named export 'Command' not found. The requested module '@nod
e-ts/bus-messages' is a CommonJS module, which may not support all module.exports as named exports.

I tried "type": "commonjs" instead "type": "module" in my package.json

import { Bus } from '@node-ts/bus-core';
 SyntaxError: Cannot use import statement outside a module

What I can do to fix it ? Thanks


Node.js v18.4.0 pnpm 7.4.1 TypeScript 4.7.4

innovaweb-dev avatar Jul 09 '22 19:07 innovaweb-dev

Temporary solution :

import pkg from '@node-ts/bus-core'
const {handlerFor}= pkg;

innovaweb-dev avatar Jul 09 '22 19:07 innovaweb-dev

hi @rifton007, it's perhaps too late by now but it looked like you were importing @node-ts/bus-messages into an ES modules-based package. There's nothing specific about the bus-messages library - it's a commonjs module.

I don't yet have a plan to move the library to ES modules, though I may end up transpiling to both. For now your temporary solution seems to be the way to go.

adenhertog avatar Feb 11 '23 05:02 adenhertog