Skip to content

Commit 6525faf

Browse files
authored
Merge pull request pyscript#25 from anaconda/mattpap/esm_import_module
Allow `import d3` instead of `from esm import d3`
2 parents 51c2efd + 0dc3b72 commit 6525faf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pyscriptjs/examples/d3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
<py-script>
111111
from pyodide import create_proxy, to_js
112-
from esm import d3
112+
import d3
113113

114114
fruits = [
115115
dict(name="🍊", count=21),

pyscriptjs/src/components/pyscript.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,6 @@ export class PyScript extends HTMLElement {
247247
}
248248

249249
protected async _register_esm(pyodide: PyodideInterface): Promise<void> {
250-
const imports: {[key: string]: unknown} = {}
251-
252250
for (const node of document.querySelectorAll("script[type='importmap']")) {
253251
const importmap = (() => {
254252
try {
@@ -265,17 +263,19 @@ export class PyScript extends HTMLElement {
265263
if (typeof name != "string" || typeof url != "string")
266264
continue
267265

266+
let exports: object
268267
try {
269268
// XXX: pyodide doesn't like Module(), failing with
270269
// "can't read 'name' of undefined" at import time
271-
imports[name] = {...await import(url)}
270+
exports = {...await import(url)}
272271
} catch {
273-
console.error(`failed to fetch '${url}' for '${name}'`)
272+
console.warn(`failed to fetch '${url}' for '${name}'`)
273+
continue
274274
}
275+
276+
pyodide.registerJsModule(name, exports)
275277
}
276278
}
277-
278-
pyodide.registerJsModule("esm", imports)
279279
}
280280

281281
async evaluate(): Promise<void> {

0 commit comments

Comments
 (0)