Page MenuHomePhabricator

user/site-wide common.js should support the ESM `import()` for Internet resources
Open, Needs TriagePublicFeature

Description

Steps to replicate the issue (include links if applicable):

  • Go to common.js
  • Save something like:
import('https://cdn.jsdelivr.net/...');
  • See Parse error: Unexpected: import on line 1 in console

What happens?:

The parser treated it as a ResourceLoader resource and parsed it wrong.

What should have happened instead?:

import() + ^http should not be parsed further.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia): 1.43.x

Other information (browser name/version, screenshots, etc.):

Event Timeline

Why not use importScriptURI? User common.js isn't an ES module.

Dragoniez renamed this task from JavaScript `import()` syntax should works for Internet resources to User common.js should support the ESM `import()` for Internet resources.Nov 4 2025, 4:10 AM
Dragoniez changed the subtype of this task from "Bug Report" to "Feature Request".
在T409139#11338574中,@Dragoniez写道:

Why not use importScriptURI? User common.js isn't an ES module.

Currently, importScriptURI does not support adding type="module".

There are many npm packages that are now only published as ESM versions. Usage like this is expected:

import('https://unpkg.com/jsx-dom?module').then(({ h }) => {
  const div = h('div')
})

Another example:

document.body.append(
  Object.assign(document.createElement('script'), {
src: 'https://cdn.jsdelivr.net/npm/@inpageedit/core/dist/index.js',
    type: 'module',
  })
)

It should be able to be abbreviated to one line (and this actually works on <= 1.35):

import('https://cdn.jsdelivr.net/npm/@inpageedit/core/dist/index.js')

import() is a JavaScript keyword, not a global function. Its semantic inconsistency in the MW produces some unexpected problems. Hope it works as much as possible like the original.

dragon-fish renamed this task from User common.js should support the ESM `import()` for Internet resources to user/site-wide common.js should support the ESM `import()` for Internet resources.Nov 7 2025, 3:57 AM