Skip to content

Error when import some type from another package #40

@edelgarat

Description

@edelgarat

I 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:

  1. When i remove 'babel-plugin-transform-typescript-metadata', this problem is missing
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    babel limitationIssues generated by babel current implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions