Skip to content

Importing a mix of types and values in an import using a custom path results in undefined imports in result JavaScript #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shimmerjs opened this issue Feb 24, 2020 · 6 comments · Fixed by #61
Labels
Bug Something isn't working Good First Issue Good for newcomers

Comments

@shimmerjs
Copy link

Given:

file1.ts:

export type Foo = 'bar';

export const baz = 'inga'; // ;)

file2.ts:

import { Foo, baz } from '@custom/scope/file1';

[...]

When the code is compiled, the Javascript import will read something like this:

file2.js:

import { Foo, baz } from '@custom/scope/file1';

but Foo will be undefined and cause errors.

@danielpza danielpza added Bug Something isn't working Good First Issue Good for newcomers labels Feb 24, 2020
@danielpza
Copy link
Member

Thank you for the bug report, good spot.

@danielpza
Copy link
Member

Hi @booninite, I've made a PR #53 that should fix this issue, I'll probably merge it and publish it to npm later today.
It seemed to be an issue with the latest versions of typescript, could you confirm this fix it for you?

@all-contributors add @booninite for bug.

@allcontributors
Copy link
Contributor

@danielpza

I've put up a pull request to add @booninite! 🎉

@shimmerjs
Copy link
Author

@danielpza I wasn't able to pick up the fix today, I should be able to try it out tomorrow and can let you know 👍

@laverdet
Copy link

laverdet commented Apr 8, 2020

It doesn't seem to be working when I try it. Sample output & configuration is below:

marcel@marcel ~/tmp $ cat tsconfig.json 
{
	"compilerOptions": {
		"target": "esnext",
		"lib": [ "esnext" ],

		"baseUrl": ".",
		"paths": {
			"~/*": [ "*" ]
		},

		"plugins": [{ "transform": "typescript-transform-paths" }]
	}
}

marcel@marcel ~/tmp $ cat index.ts 
import { Format, value } from '~/format';
console.log(value);

marcel@marcel ~/tmp $ cat format.ts 
export type Format = number;
export const value = 1;

marcel@marcel ~/tmp $ npx ttsc
marcel@marcel ~/tmp $ cat index.js 
import { Format, value } from "./format";
console.log(value);

marcel@marcel ~/tmp $ cat package.json 
{
  "name": "tmp",
  "dependencies": {
    "ttypescript": "^1.5.10",
    "typescript": "^3.8.3",
    "typescript-transform-paths": "file:../code/typescript-transform-paths"
  }
}

marcel@marcel ~/tmp $ cd ../code/typescript-transform-paths/

marcel@marcel ~/code/typescript-transform-paths $ git rev-parse HEAD
ca44c057f656b3a17c3ad35dc0275def7e0f3515

@dimikot
Copy link

dimikot commented May 4, 2020

@danielpza
Unfortunately PR #53 doesn't help, still the same effect.

Here is a with minimal code which reproduces the issue: https://github.com/DmitryKoterov/typescript-transform-paths-bug - could you please take a look?

Those excess import symbols don't allow to use es6 modules since node complains on an attempt to import an undefined symbol:

image

danielpza pushed a commit that referenced this issue Jul 30, 2020
* Multiple Issue Fixes

- Allow more than one path routing (fixes #60)
- Remove implicit extensions from output (fixes #24)
- Properly implemented isTypeOnly (fixes #48)
- Corrected errors in tests due to TS changing logic for type only star exports
- Bonus: Made package zero-dependency

* Removed accidental dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Good First Issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants