developit / developit/microbundle

Cannot import external es6 module correctly

Ouverte
#881 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
8.1k
Forks
358
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I have a typescript project, the ts files are stored in different directories, they all import the same external module, like this:

/main.ts:

```
import * as ext from 'external';
import { g } from './lib/foo';
function f() {
g();
ext.func1();
}
```

/lib/foo.ts:

```
import * as ext from 'external';
function g() {
ext.func2();
}
```

I want to package main.ts into an ES6 module and store it in the same directory as external.js
After packaging, I expected to get this result:

main.js:

```
import * as ext from './external.js";
// blah blah
```

My packaging script looks like this:

```
microbundle -i main.ts --no-pkg-main -f modern --target web -o dist/main.js --external .*/external.js --alias external=./external.js

```

But I got this result:

```
import * as ext$1 from './external.js';
import * as ext from './lib/external.js';
```

I think this should be because the two ts files are in different directories and aliases are used, but what should be the correct way?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Reproduce the packaging command with main.ts, lib/foo.ts, and the external module, then inspect dist/main.js. Compare how each source import is resolved and verify that both references to external produce the intended shared ./external.js import. The issue is done when the generated ES6 module has the expected external import without the incorrect lib/external.js path.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, typescript
Domaine
build-system, tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.