developit / developit/microbundle

Cannot import external es6 module correctly

Aperta
#881 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
8.1k
Fork
358
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
build-system, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.