You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two projects - angular 13 library and my-tool.
My-tool analyzes angular project .ts files and does some processing.... My-tool has a bin section in package.json. So, to run my-tool I do in angular library root npx my-tool. My-tool is created via rollup and has the following shebang: #!/usr/bin/env ts-node. Test code in my-tool is the following (it just creates instances of the passed classes from angular library):
for (let i = 0; i < classes.length; i++) {
let classPath = classes[i];
import(path.resolve(this._basePath, classPath)).then(module => {
for (const className in module.default) {
let c = new module.default[className]();
console.log(c);
}
});
}
when my-tool is used for processing angular library code it uses the following tsconfig:
In both angular library (.ts) and my-tool library (.ts) to use logger I do: import { Logger, LoggerFactory } from '@dz/logjs'. And this code is compiled and works without any problems. However, when in my-tool I try to import(classPath) a class that has import { Logger, LoggerFactory } from '@dz/logjs', I get:
/home/pavel/mylib/node_modules/ts-node/src/index.ts:843
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
projects/core/src/abstract-foo-entity.ts:12:39 - error TS1471: Module '@dz/logjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
12 import { Logger, LoggerFactory } from '@dz/logjs';
~~~~~~~~~~~~
at createTSError (/home/pavel/mylib/node_modules/ts-node/src/index.ts:843:12)
at reportTSError (/home/pavel/mylib/node_modules/ts-node/src/index.ts:847:19)
at getOutput (/home/pavel/mylib/node_modules/ts-node/src/index.ts:1057:36)
at Object.compile (/home/pavel/mylib/node_modules/ts-node/src/index.ts:1411:41)
at Module.m._compile (/home/pavel/mylib/node_modules/ts-node/src/index.ts:1596:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Object.require.extensions.<computed> [as .ts] (/home/pavel/mylib/node_modules/ts-node/src/index.ts:1600:12)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29) {
diagnosticCodes: [ 1471 ]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have two projects - angular 13 library and my-tool.
My-tool analyzes angular project .ts files and does some processing.... My-tool has a bin section in package.json. So, to run my-tool I do in angular library root
npx my-tool
. My-tool is created via rollup and has the following shebang:#!/usr/bin/env ts-node
. Test code in my-tool is the following (it just creates instances of the passed classes from angular library):when my-tool is used for processing angular library code it uses the following tsconfig:
Both angular library and my-tool uses logging library. This logging library is an ES module. This is a piece of package.json of this logging library:
In both angular library (.ts) and my-tool library (.ts) to use logger I do:
import { Logger, LoggerFactory } from '@dz/logjs'
. And this code is compiled and works without any problems. However, when in my-tool I try to import(classPath) a class that hasimport { Logger, LoggerFactory } from '@dz/logjs'
, I get:Could you say how to fix it?
Beta Was this translation helpful? Give feedback.
All reactions