Error when import some type from another package
See original GitHub issueI have an issue, when I import some type from package (linked or regular) problem like: can’t resolve “path/to/my/node_modules/module” or “my type” is not exported from ‘path/to/my/module’.
Error:
babel-ts-decorator-error@1.0.0 start /Users/edelgarat/Documents/projects/babel-ts-decorator-error webpack
[webpack-cli] Compilation finished asset bundle.js 59 KiB [emitted] (name: main) runtime modules 1.13 KiB 5 modules cacheable modules 52 KiB ./src/index.ts 1.95 KiB [built] [code generated] ./node_modules/reflect-metadata/Reflect.js 50 KiB [built] [code generated]
ERROR in ./src/index.ts 10:0-73 Module not found: Error: Can’t resolve ‘test-package/file-with-declaration’ in ‘/Users/edelgarat/Documents/projects/babel-ts-decorator-error/src’
webpack 5.6.0 compiled with 1 error in 631 ms npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! babel-ts-decorator-error@1.0.0 start:
webpack
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the babel-ts-decorator-error@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in: npm ERR! /Users/edelgarat/.npm/_logs/2020-11-22T18_10_36_504Z-debug.log
Notes:
- When i remove ‘babel-plugin-transform-typescript-metadata’, this problem is missing
- When i remove “@decorator”, this problem is missing
Entry point file:
import {SomeTypeDeclaration} from "test-package/file-with-declaration";
const someDecorator: PropertyDecorator = (target, propertyKey) => {}
class Test {
@someDecorator
someProperty: SomeTypeDeclaration = 5;
}
Error:
Module not found: Error: Can’t resolve ‘test-package/file-with-declaration’ in ‘/Users/edelgarat/Documents/projects/babel-ts-decorator-error/src’
Webpack babel rule:
{
test: /\.ts$/,
use: {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-typescript", {}]
],
plugins: [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }],
"babel-plugin-transform-typescript-metadata",
]
}
}
}
Demo project: https://github.com/edelgarat/babel-plugin-transform-typescript-metadata-import-error
Test stand:
- Mac OS 10.15.4
- Node v14.2.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I updated the repository to see the problem better
new code:
new error:
if you compile through typescript, then for the property “a” property this will be:
but, as I understand it, this plugin (or babel) thinks that “IKeyValueMap” is an entity that can be accessed from js
Using values as types seems an issue linked to #46. Could you try to use
import type { ... }
in order to give babel a hint? Since we don’t have access to TS Checker, type information is not accessible so we cannot distinguish between interfaces and concrete types.