Skip to content

[rfc] Support import.meta with experimentalImportSupport - #1494

Draft
robhogan wants to merge 1 commit into
mainfrom
pr1494
Draft

[rfc] Support import.meta with experimentalImportSupport#1494
robhogan wants to merge 1 commit into
mainfrom
pr1494

Conversation

@robhogan

@robhogan robhogan commented Apr 27, 2025

Copy link
Copy Markdown
Contributor

Currently, Metro leaves import.meta accesses untransformed, but provides no import pseudoglobal, so (unless polyfilled) this throws at runtime.

import.meta is specified as a writable null-proto object. Though the spec is silent on any properties, it provides a mechanism (HostGetImportMetaProperties) for hosts to set properties, given a module object. Eg: url, resolve are defined by Node.js and browsers (and notably env by Vite).

We emulate that mechanism here with the __getImportMetaProperties(module) => {[key: string]: mixed} optional, framework-defined global function.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 27, 2025
@satya164

Copy link
Copy Markdown
Contributor

What do you think about adding import.meta.resolve in addition to import.meta.url?

It's supported in both browsers and node, and would be a replacement for require.resolve.

@robhogan

robhogan commented Apr 27, 2025

Copy link
Copy Markdown
Contributor Author

What do you think about adding import.meta.resolve in addition to import.meta.url?

It's supported in both browsers and node, and would be a replacement for require.resolve.

The plan is for RN (or Expo) to define properties using the __getImportMetaProperties hook, which is analogous to host-defined props in the ES spec (HostGetImportMetaProperties) - Metro doesn't define url either (it does here only in an integration test).

Metro could define some more defaults though..

Comment on lines +31 to +34
__getImportMetaProperties: module => {
return {
url: new URL(String(module.id), 'metro://'),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this code will be added to react native itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, Metro leaves `import.meta` accesses untransformed, but provides no `import` pseudoglobal, so (unless polyfilled) this throws at runtime.

`import.meta` is [specified](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-meta-properties) as a writable null-proto object. Though the spec is silent on any properties, it provides a mechanism ([`HostGetImportMetaProperties`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-hostgetimportmetaproperties)) for hosts to set properties, given a module object. Eg: `url`, `resolve` are defined by Node.js and browsers (and notably `env` by Vite).

We emulate that mechanism here with the `__getImportMetaProperties(module) => {[key: string]: mixed}` optional, framework-defined global function.
@IgnisDa

IgnisDa commented May 2, 2026

Copy link
Copy Markdown

any progress on this?

IgnisDa added a commit to IgnisDa/ryot that referenced this pull request May 2, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request May 31, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request May 31, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 13, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 13, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 15, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 15, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 15, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 19, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 20, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 24, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 24, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 24, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 24, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 26, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
IgnisDa added a commit to IgnisDa/ryot that referenced this pull request Jul 26, 2026
Metro 0.82+ (Expo 53+) enables package.json exports by default. When
source uses ESM import syntax, Metro asserts the 'import' condition,
which resolves jotai to its .mjs build containing import.meta.env.MODE
— a Vite-ism. Metro's web output is a plain <script> (not type=module),
so the browser throws a SyntaxError before any app code runs.

babel-preset-expo gained unstable_transformImportMeta in SDK 53 as an
opt-in to compile import.meta away at build time. Enabling it here is
the correct fix; no metro.config.js changes needed.

Tracked: pmndrs/jotai#3041
Metro fix in progress: react/metro#1494

Generated-by: OpenCode
Model: amazon-bedrock/anthropic.claude-sonnet-4-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants