feat(turbopack): support import.meta.env (#96225)

## Summary

- add native Turbopack support for `import.meta.env.DEV`, `PROD`,
`MODE`, `BASE_URL`, and `SSR`
- statically analyze built-in values for dead-code elimination while
exposing the complete runtime object
- derive `BASE_URL` from the Next.js `basePath` and include
Vite-compatible trailing-slash formatting
- add TypeScript declarations, focused execution and Next.js integration
coverage, and Vite migration documentation

## Verification

- `cargo fmt --all -- --check`
- `cargo nextest run -p turbopack-tests -E 'test(import_meta_env)'`
- `pnpm build-all`
- `pnpm --filter=next types`
- `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-turbo
test/e2e/import-meta-env/import-meta-env.test.ts`
- `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-turbo
test/e2e/import-meta-env/import-meta-env.test.ts`

<!-- NEXT_JS_LLM -->
This commit is contained in:
Tim Neutkens
2026-07-28 17:34:04 +00:00
committed by GitHub
parent 1de0812714
commit c23d1a946c
40 changed files with 440 additions and 47 deletions
+10
View File
@@ -989,6 +989,13 @@ pub struct ProjectDefineEnv {
nodejs: ResolvedVc<OptionEnvMap>,
}
async fn import_meta_env_base_url(next_config: ResolvedVc<NextConfig>) -> Result<RcStr> {
Ok(match &*next_config.base_path().await? {
Some(base_path) => format!("{base_path}/").into(),
None => rcstr!("/"),
})
}
#[turbo_tasks::value_impl]
impl ProjectDefineEnv {
#[turbo_tasks::function]
@@ -1280,6 +1287,7 @@ impl Project {
self.define_env.client(),
self.next_config.report_system_env_inlining(),
next_mode.is_development(),
import_meta_env_base_url(self.next_config).await?,
))
}
@@ -1555,6 +1563,7 @@ impl Project {
self.current_node_js_version(),
this.next_config.report_system_env_inlining(),
this.server_hmr,
import_meta_env_base_url(this.next_config).await?,
))
}
@@ -1566,6 +1575,7 @@ impl Project {
this.define_env.edge(),
self.current_node_js_version(),
this.next_config.report_system_env_inlining(),
import_meta_env_base_url(this.next_config).await?,
))
}
@@ -106,6 +106,7 @@ pub async fn get_client_compile_time_info(
define_env: Vc<OptionEnvMap>,
report_system_env_inlining: Vc<IssueSeverity>,
hot_module_replacement_enabled: bool,
import_meta_env_base_url: RcStr,
) -> Result<Vc<CompileTimeInfo>> {
CompileTimeInfo::builder(
Environment::new(ExecutionEnvironment::Browser(
@@ -127,6 +128,7 @@ pub async fn get_client_compile_time_info(
.await?,
)
.hot_module_replacement_enabled(hot_module_replacement_enabled)
.import_meta_env_base_url(import_meta_env_base_url)
.cell()
.await
}
@@ -70,6 +70,7 @@ pub async fn get_edge_compile_time_info(
define_env: Vc<OptionEnvMap>,
node_version: ResolvedVc<NodeJsVersion>,
report_system_env_inlining: Vc<IssueSeverity>,
import_meta_env_base_url: RcStr,
) -> Result<Vc<CompileTimeInfo>> {
CompileTimeInfo::builder(
Environment::new(ExecutionEnvironment::EdgeWorker(
@@ -84,6 +85,7 @@ pub async fn get_edge_compile_time_info(
.to_resolved()
.await?,
)
.import_meta_env_base_url(import_meta_env_base_url)
.cell()
.await
}
@@ -336,6 +336,7 @@ pub async fn get_server_compile_time_info(
node_version: ResolvedVc<NodeJsVersion>,
report_system_env_inlining: Vc<IssueSeverity>,
hot_module_replacement_enabled: bool,
import_meta_env_base_url: RcStr,
) -> Result<Vc<CompileTimeInfo>> {
CompileTimeInfo::builder(
Environment::new(ExecutionEnvironment::NodeJsLambda(
@@ -356,6 +357,7 @@ pub async fn get_server_compile_time_info(
.await?,
)
.hot_module_replacement_enabled(hot_module_replacement_enabled)
.import_meta_env_base_url(import_meta_env_base_url)
.cell()
.await
}
+7 -21
View File
@@ -525,13 +525,10 @@ client-side.
- Change all environment variables with the `VITE_` prefix to `NEXT_PUBLIC_`.
Vite exposes a few built-in environment variables on the special `import.meta.env` object which
aren’t supported by Next.js. You need to update their usage as follows:
- `import.meta.env.MODE` ⇒ `process.env.NODE_ENV`
- `import.meta.env.PROD` ⇒ `process.env.NODE_ENV === 'production'`
- `import.meta.env.DEV` ⇒ `process.env.NODE_ENV !== 'production'`
- `import.meta.env.SSR` ⇒ `typeof window !== 'undefined'`
Turbopack supports Vite's built-in `import.meta.env.MODE`, `DEV`, `PROD`, `BASE_URL`, and `SSR`
properties with no changes needed. `BASE_URL` reflects the Next.js
[`basePath`](/docs/app/api-reference/config/next-config-js/basePath) configuration and includes a
trailing slash, matching Vite's format.
**`import.meta.glob`** is supported by Turbopack (the default Next.js bundler) with no changes needed. If you were using the `as` option (deprecated in Vite 5), replace it with `query`:
@@ -545,31 +542,20 @@ const modules = import.meta.glob('./dir/*.txt', { query: '?raw' })
See the [import.meta.glob docs](/docs/app/api-reference/turbopack#importmetaglob) for the full API.
Next.js also doesn't provide a built-in `BASE_URL` environment variable. However, you can still
configure one, if you need it:
1. **Add the following to your `.env` file:**
```bash filename=".env"
# ...
NEXT_PUBLIC_BASE_PATH="/some-base-path"
```
2. **Set [`basePath`](/docs/app/api-reference/config/next-config-js/basePath) to `process.env.NEXT_PUBLIC_BASE_PATH` in your `next.config.mjs` file:**
If your Vite application configured a custom base URL, set the equivalent
[`basePath`](/docs/app/api-reference/config/next-config-js/basePath) in your `next.config.mjs` file:
```js filename="next.config.mjs"
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // Outputs a Single-Page Application (SPA).
distDir: './dist', // Changes the build output directory to `./dist/`.
basePath: process.env.NEXT_PUBLIC_BASE_PATH, // Sets the base path to `/some-base-path`.
basePath: '/some-base-path',
}
export default nextConfig
```
3. **Update `import.meta.env.BASE_URL` usages to `process.env.NEXT_PUBLIC_BASE_PATH`**
### Step 8: Update Scripts in `package.json`
You should now be able to run your application to test if you successfully migrated to Next.js. But
@@ -137,6 +137,35 @@ Turbopack supports webpack-compatible magic comments for controlling import beha
See [Lazy Loading](/docs/app/guides/lazy-loading#magic-comments) for usage examples.
## import.meta.env
Turbopack supports built-in environment metadata through `import.meta.env`:
| Property | Type | Value |
| ---------- | --------- | ------------------------------------------------------------------ |
| `DEV` | `boolean` | Whether `MODE` is not `"production"` |
| `PROD` | `boolean` | Whether `MODE` is `"production"` |
| `MODE` | `string` | The compile-time `NODE_ENV`, defaulting to `"development"` |
| `BASE_URL` | `string` | The Next.js `basePath`, with a trailing slash (`"/"` by default) |
| `SSR` | `boolean` | `true` in server bundles and `false` in browser and client bundles |
These values are statically analyzed, so Turbopack can remove unreachable branches:
```ts filename="app/example.ts"
if (import.meta.env.DEV) {
console.log('development mode')
}
```
You can also read the whole object, destructure it, or use static bracket access:
```ts filename="app/example.ts"
const { MODE, SSR } = import.meta.env
const baseUrl = import.meta.env['BASE_URL']
```
> **Good to know**: `import.meta.env` requires Turbopack. Custom `VITE_*` variables, Vite custom modes, `envPrefix`, and `envDir` are not supported. `BASE_URL` reflects the Next.js [`basePath`](/docs/app/api-reference/config/next-config-js/basePath) configuration and includes a trailing slash to match Vite's format.
## import.meta.glob
Turbopack supports `import.meta.glob()`, a Vite-compatible API for importing multiple modules at once using glob patterns. The result is an object keyed by the file path relative to the calling file.
+13
View File
@@ -100,7 +100,20 @@ interface ImportMetaGlobOptions {
caseSensitive?: boolean
}
interface ImportMetaEnv {
readonly DEV: boolean
readonly PROD: boolean
readonly MODE: string
readonly BASE_URL: string
readonly SSR: boolean
}
interface ImportMeta {
/**
* Built-in environment metadata when using Turbopack.
*/
readonly env: ImportMetaEnv
/**
* The HMR API for ESM modules when using Turbopack.
* Equivalent to `module.hot` in CommonJS modules.
@@ -0,0 +1,31 @@
'use client'
import { useEffect, useState } from 'react'
const env = import.meta.env
const { DEV, PROD, MODE, BASE_URL, SSR } = env
const bracketMode = import.meta.env['MODE']
const unknown = (env as unknown as Record<string, unknown>).UNKNOWN
export function ClientEnv() {
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
if (!mounted) {
return <div id="client-env-pending" />
}
return (
<dl id="client-env">
<dt>env</dt>
<dd>{JSON.stringify({ DEV, PROD, MODE, BASE_URL, SSR })}</dd>
<dt>bracket-mode</dt>
<dd>{bracketMode}</dd>
<dt>unknown</dt>
<dd>{String(unknown)}</dd>
</dl>
)
}
+7
View File
@@ -0,0 +1,7 @@
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
+30
View File
@@ -0,0 +1,30 @@
import { ClientEnv } from './client-env'
const env = import.meta.env
const { DEV, PROD, MODE, BASE_URL, SSR } = env
const bracketMode = import.meta.env['MODE']
const unknown = (env as unknown as Record<string, unknown>).UNKNOWN
if (!import.meta.env.SSR) {
require('this-server-only-package-does-not-exist')
}
if (import.meta.env.DEV && import.meta.env.PROD) {
require('this-impossible-package-does-not-exist')
}
export default function Page() {
return (
<main>
<dl id="server-env">
<dt>env</dt>
<dd>{JSON.stringify({ DEV, PROD, MODE, BASE_URL, SSR })}</dd>
<dt>bracket-mode</dt>
<dd>{bracketMode}</dd>
<dt>unknown</dt>
<dd>{String(unknown)}</dd>
</dl>
<ClientEnv />
</main>
)
}
@@ -0,0 +1,54 @@
import { isNextDev, nextTestSetup } from 'e2e-utils'
const testFn =
process.env.IS_WEBPACK_TEST || process.env.NEXT_RSPACK
? describe.skip
: describe
testFn('import.meta.env', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) return
it('exposes built-in environment values on the server and client', async () => {
const browser = await next.browser('/docs')
const expectedMode = isNextDev ? 'development' : 'production'
expect(
JSON.parse(await browser.elementByCss('#server-env dd').text())
).toEqual({
DEV: isNextDev,
PROD: !isNextDev,
MODE: expectedMode,
BASE_URL: '/docs/',
SSR: true,
})
expect(
JSON.parse(await browser.elementByCss('#client-env dd').text())
).toEqual({
DEV: isNextDev,
PROD: !isNextDev,
MODE: expectedMode,
BASE_URL: '/docs/',
SSR: false,
})
})
it('supports static bracket access and unknown properties', async () => {
const browser = await next.browser('/docs')
const $ = await next.render$('/docs')
const expectedMode = isNextDev ? 'development' : 'production'
expect($('#server-env dd').eq(1).text()).toBe(expectedMode)
expect($('#server-env dd').eq(2).text()).toBe('undefined')
expect(
await browser.elementByCss('#client-env dd:nth-of-type(2)').text()
).toBe(expectedMode)
expect(
await browser.elementByCss('#client-env dd:nth-of-type(3)').text()
).toBe('undefined')
})
})
+4
View File
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
module.exports = {
basePath: '/docs',
}
@@ -4,7 +4,7 @@ use indexmap::Equivalent;
use num_bigint::BigInt;
use rustc_hash::FxHashSet;
use smallvec::{SmallVec, smallvec};
use turbo_rcstr::RcStr;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{FxIndexMap, NonLocalValue, ResolvedVc, Vc, trace::TraceRawVcs};
use turbo_tasks_fs::FileSystemPath;
@@ -432,6 +432,7 @@ pub struct CompileTimeInfo {
pub defines: ResolvedVc<CompileTimeDefines>,
pub free_var_references: ResolvedVc<FreeVarReferences>,
pub hot_module_replacement_enabled: bool,
pub import_meta_env_base_url: RcStr,
}
impl CompileTimeInfo {
@@ -441,6 +442,7 @@ impl CompileTimeInfo {
defines: None,
free_var_references: None,
hot_module_replacement_enabled: false,
import_meta_env_base_url: rcstr!("/"),
}
}
}
@@ -454,6 +456,7 @@ impl CompileTimeInfo {
defines: CompileTimeDefines::empty().to_resolved().await?,
free_var_references: FreeVarReferences::empty().to_resolved().await?,
hot_module_replacement_enabled: false,
import_meta_env_base_url: rcstr!("/"),
}
.cell())
}
@@ -469,6 +472,7 @@ pub struct CompileTimeInfoBuilder {
defines: Option<ResolvedVc<CompileTimeDefines>>,
free_var_references: Option<ResolvedVc<FreeVarReferences>>,
hot_module_replacement_enabled: bool,
import_meta_env_base_url: RcStr,
}
impl CompileTimeInfoBuilder {
@@ -490,6 +494,11 @@ impl CompileTimeInfoBuilder {
self
}
pub fn import_meta_env_base_url(mut self, base_url: RcStr) -> Self {
self.import_meta_env_base_url = base_url;
self
}
pub async fn build(self) -> Result<CompileTimeInfo> {
Ok(CompileTimeInfo {
environment: self.environment,
@@ -502,6 +511,7 @@ impl CompileTimeInfoBuilder {
None => FreeVarReferences::empty().to_resolved().await?,
},
hot_module_replacement_enabled: self.hot_module_replacement_enabled,
import_meta_env_base_url: self.import_meta_env_base_url,
})
}
@@ -32,6 +32,7 @@ pub enum WellKnownObjectKind {
NodeBuffer,
RequireCache,
ImportMeta,
ImportMetaEnv,
/// An iterator object, used to model generator return values.
Generator,
/// The `module.hot` object providing HMR API.
@@ -140,6 +141,7 @@ impl WellKnownObjectKind {
"The CommonJS require.cache object: https://nodejs.org/api/modules.html#requirecache",
),
Self::ImportMeta => ("import.meta", "The import.meta object"),
Self::ImportMetaEnv => ("import.meta.env", "The import.meta.env object"),
Self::ModuleHot => ("module.hot", "The module.hot HMR API"),
Self::Navigator => (
"navigator",
@@ -8,7 +8,7 @@ use either::Either;
use smallvec::SmallVec;
use turbo_rcstr::rcstr;
use turbo_tasks::Vc;
use turbopack_core::compile_time_info::CompileTimeInfo;
use turbopack_core::{compile_time_info::CompileTimeInfo, environment::Rendering};
use url::Url;
use super::{
@@ -718,6 +718,7 @@ async fn well_known_object_member<'a>(
WellKnownObjectKind::NodeExpressApp => express(arena.get_or_default(), prop),
WellKnownObjectKind::NodeProtobufLoader => protobuf_loader(arena.get_or_default(), prop),
WellKnownObjectKind::ImportMeta => match prop.as_str() {
Some("env") => JsValue::WellKnownObject(WellKnownObjectKind::ImportMetaEnv),
// import.meta.turbopackHot is the ESM equivalent of module.hot for HMR
Some("turbopackHot") if compile_time_info.await?.hot_module_replacement_enabled => {
JsValue::WellKnownObject(WellKnownObjectKind::ModuleHot)
@@ -733,6 +734,40 @@ async fn well_known_object_member<'a>(
));
}
},
WellKnownObjectKind::ImportMetaEnv => {
let compile_time_info = compile_time_info.await?;
let mode = compile_time_info
.defines
.read_process_env(rcstr!("NODE_ENV"))
.owned()
.await?
.unwrap_or_else(|| rcstr!("development"));
let is_prod = mode == "production";
match prop.as_str() {
Some("MODE") => JsValue::from(mode),
Some("PROD") => JsValue::from(ConstantValue::from(is_prod)),
Some("DEV") => JsValue::from(ConstantValue::from(!is_prod)),
Some("BASE_URL") => {
JsValue::from(compile_time_info.import_meta_env_base_url.clone())
}
Some("SSR") => JsValue::from(ConstantValue::from(matches!(
*compile_time_info.environment.rendering().await?,
Rendering::Server
))),
Some(_) => JsValue::Constant(ConstantValue::Undefined),
None => {
return Ok((
JsValue::member(
arena.get_or_default(),
JsValue::WellKnownObject(kind),
prop,
),
Modified::No,
));
}
}
}
WellKnownObjectKind::ModuleHot => match prop.as_str() {
Some("accept") => JsValue::WellKnownFunction(WellKnownFunctionKind::ModuleHotAccept),
Some("decline") => JsValue::WellKnownFunction(WellKnownFunctionKind::ModuleHotDecline),
@@ -7,7 +7,7 @@ use swc_core::{
ecma::ast::{Expr, Ident},
quote,
};
use turbo_rcstr::rcstr;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{NonLocalValue, Vc, debug::ValueDebugFormat, trace::TraceRawVcs};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::chunk::ChunkingContext;
@@ -32,11 +32,26 @@ use crate::{
pub struct ImportMetaBinding {
path: FileSystemPath,
hmr_enabled: bool,
mode: RcStr,
base_url: RcStr,
is_ssr: bool,
}
impl ImportMetaBinding {
pub fn new(path: FileSystemPath, hmr_enabled: bool) -> Self {
ImportMetaBinding { path, hmr_enabled }
pub fn new(
path: FileSystemPath,
hmr_enabled: bool,
mode: RcStr,
base_url: RcStr,
is_ssr: bool,
) -> Self {
ImportMetaBinding {
path,
hmr_enabled,
mode,
base_url,
is_ssr,
}
}
pub async fn code_generation(
@@ -68,6 +83,11 @@ impl ImportMetaBinding {
);
let hmr_enabled = self.hmr_enabled;
let mode: Expr = self.mode.as_str().into();
let is_prod: Expr = (self.mode == "production").into();
let is_dev: Expr = (self.mode != "production").into();
let is_ssr: Expr = self.is_ssr.into();
let base_url: Expr = self.base_url.as_str().into();
// [NOTE] url property is lazy-evaluated, as it should be computed once
// turbopack_runtime injects a function to calculate an absolute path.
@@ -75,16 +95,29 @@ impl ImportMetaBinding {
// turbopackHot exposes the HMR API (equivalent to module.hot in CJS).
let turbopack_module: Expr = TURBOPACK_MODULE.into();
quote!(
"var $name = { get url() { return $path }, get turbopackHot() { return $m.hot } };" as Stmt,
"var $name = { get url() { return $path }, env: { DEV: $is_dev, PROD: \
$is_prod, MODE: $mode, BASE_URL: $base_url, SSR: $is_ssr }, get turbopackHot() { \
return $m.hot } };" as Stmt,
name = meta_ident(),
path: Expr = path,
is_dev: Expr = is_dev,
is_prod: Expr = is_prod,
mode: Expr = mode,
base_url: Expr = base_url,
is_ssr: Expr = is_ssr,
m: Expr = turbopack_module,
)
} else {
quote!(
"var $name = { get url() { return $path } };" as Stmt,
"var $name = { get url() { return $path }, env: { DEV: $is_dev, PROD: \
$is_prod, MODE: $mode, BASE_URL: $base_url, SSR: $is_ssr } };" as Stmt,
name = meta_ident(),
path: Expr = path,
is_dev: Expr = is_dev,
is_prod: Expr = is_prod,
mode: Expr = mode,
base_url: Expr = base_url,
is_ssr: Expr = is_ssr,
)
};
@@ -1383,11 +1383,32 @@ async fn analyze_ecmascript_module_internal(
);
if analysis_state.first_import_meta {
analysis_state.first_import_meta = false;
let mode = analysis_state
.compile_time_info_ref
.defines
.read_process_env(rcstr!("NODE_ENV"))
.owned()
.await?
.unwrap_or_else(|| rcstr!("development"));
let is_ssr = matches!(
*analysis_state
.compile_time_info_ref
.environment
.rendering()
.await?,
Rendering::Server
);
analysis.add_code_gen(ImportMetaBinding::new(
source.ident().await?.path.clone(),
analysis_state
.compile_time_info_ref
.hot_module_replacement_enabled,
mode,
analysis_state
.compile_time_info_ref
.import_meta_env_base_url
.clone(),
is_ssr,
));
}
@@ -1529,6 +1550,7 @@ async fn compile_time_info_for_module_options(
defines: CompileTimeDefines(defines).resolved_cell(),
free_var_references: FreeVarReferences(free_var_references).resolved_cell(),
hot_module_replacement_enabled: compile_time_info.hot_module_replacement_enabled,
import_meta_env_base_url: compile_time_info.import_meta_env_base_url.clone(),
}
.cell())
}
@@ -0,0 +1,30 @@
const env = import.meta.env
const { DEV, PROD, MODE, BASE_URL, SSR } = env
it('exposes built-in import.meta.env values', () => {
expect({ DEV, PROD, MODE, BASE_URL, SSR }).toEqual({
DEV: false,
PROD: true,
MODE: 'production',
BASE_URL: '/',
SSR: true,
})
expect(import.meta.env['MODE']).toBe('production')
expect(env.UNKNOWN).toBe(undefined)
})
if (import.meta.env.DEV) {
require('this-development-package-does-not-exist')
}
if (!import.meta.env.PROD) {
require('this-non-production-package-does-not-exist')
}
if (!import.meta.env.SSR) {
require('this-browser-package-does-not-exist')
}
if (import.meta.env.DEV && import.meta.env.PROD) {
require('this-impossible-package-does-not-exist')
}
@@ -4,6 +4,13 @@
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/cjs.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log('typeof require', ("TURBOPACK compile-time value", "function"));
@@ -25,6 +32,13 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbo
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-automatic.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
;
@@ -43,6 +57,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-specified.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log('typeof require', ("TURBOPACK compile-time value", "function"));
@@ -2,9 +2,9 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 3, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/cjs.js"],"sourcesContent":["console.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// CJS, should be `object`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// CJS, should be real require\nconsole.log(require)\n"],"names":["console","log"],"mappings":";;;;;AAAAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,0BAA0B;AAC1BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 18, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}},
{"offset": {"line": 22, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-automatic.js"],"sourcesContent":["import './dep.js'\n\nconsole.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// ESM, should be `undefined`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// ESM, should be require stub\nconsole.log(require)\n"],"names":["console","log"],"mappings":";AAAA;;;;;;;AAEAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,6BAA6B;AAC7BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 41, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-specified.mjs"],"sourcesContent":["console.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// ESM, should be `undefined`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// ESM, should be require stub\nconsole.log(require)\n"],"names":["console","log"],"mappings":";;;;;;AAAAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,6BAA6B;AAC7BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 58, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/index.js"],"sourcesContent":["import './cjs.js'\nimport './esm-automatic.js'\nimport './esm-specified.mjs'\n"],"names":[],"mappings":";AAAA;AACA;AACA"}}]
{"offset": {"line": 3, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/cjs.js"],"sourcesContent":["console.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// CJS, should be `object`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// CJS, should be real require\nconsole.log(require)\n"],"names":["console","log"],"mappings":";;;;;;;;;;;;AAAAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,0BAA0B;AAC1BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 25, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}},
{"offset": {"line": 29, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-automatic.js"],"sourcesContent":["import './dep.js'\n\nconsole.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// ESM, should be `undefined`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// ESM, should be require stub\nconsole.log(require)\n"],"names":["console","log"],"mappings":";AAAA;;;;;;;;;;;;;;AAEAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,6BAA6B;AAC7BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 55, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-specified.mjs"],"sourcesContent":["console.log('typeof require', typeof require)\nconsole.log('typeof import.meta', typeof import.meta)\n// ESM, should be `undefined`\nconsole.log('typeof module', typeof module)\nconsole.log('typeof exports', typeof exports)\n\n// ESM, should be require stub\nconsole.log(require)\n"],"names":["console","log"],"mappings":";;;;;;;;;;;;;AAAAA,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AACZ,6BAA6B;AAC7BD,QAAQC,GAAG,CAAC;AACZD,QAAQC,GAAG,CAAC;AAEZ,8BAA8B;AAC9BD,QAAQC,GAAG"}},
{"offset": {"line": 79, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/index.js"],"sourcesContent":["import './cjs.js'\nimport './esm-automatic.js'\nimport './esm-specified.mjs'\n"],"names":[],"mappings":";AAAA;AACA;AACA"}}]
}
@@ -8,6 +8,13 @@ var __TURBOPACK__url__external__node$3a$fs__ = __turbopack_context__.x("node:fs"
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: true
}
};
;
@@ -2,5 +2,5 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js"],"sourcesContent":["import child_process from 'node:child_process'\nimport fs, { readFileSync } from 'node:fs'\n\nconst unknown = Math.random()\n\nchild_process.spawnSync(unknown)\nchild_process.spawnSync('node', unknown)\nchild_process.spawnSync('node', [unknown, unknown])\n\nrequire(unknown)\n\nimport(unknown)\n\nfs.readFileSync(unknown)\nreadFileSync(unknown)\n\nnew URL(unknown, import.meta.url)\n"],"names":["unknown","Math","random","spawnSync","readFileSync","URL","url"],"mappings":";AAAA;AACA;;;;;;;;AAEA,MAAMA,UAAUC,KAAKC,MAAM;AAE3B,8DAAa,CAACC,SAAS,CAACH;AACxB,8DAAa,CAACG,SAAS,CAAC,QAAQH;AAChC,8DAAa,CAACG,SAAS,CAAC,QAAQ;IAACH;IAASA;CAAQ;;;;;;;;;;;AAMlD,mDAAE,CAACI,YAAY,CAACJ;AAChB,IAAA,wDAAY,EAACA;AAEb,IAAIK,IAAIL,SAAS,8BAAYM,GAAG"}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js"],"sourcesContent":["import child_process from 'node:child_process'\nimport fs, { readFileSync } from 'node:fs'\n\nconst unknown = Math.random()\n\nchild_process.spawnSync(unknown)\nchild_process.spawnSync('node', unknown)\nchild_process.spawnSync('node', [unknown, unknown])\n\nrequire(unknown)\n\nimport(unknown)\n\nfs.readFileSync(unknown)\nreadFileSync(unknown)\n\nnew URL(unknown, import.meta.url)\n"],"names":["unknown","Math","random","spawnSync","readFileSync","URL","url"],"mappings":";AAAA;AACA;;;;;;;;;;;;;;;AAEA,MAAMA,UAAUC,KAAKC,MAAM;AAE3B,8DAAa,CAACC,SAAS,CAACH;AACxB,8DAAa,CAACG,SAAS,CAAC,QAAQH;AAChC,8DAAa,CAACG,SAAS,CAAC,QAAQ;IAACH;IAASA;CAAQ;;;;;;;;;;;AAMlD,mDAAE,CAACI,YAAY,CAACJ;AAChB,IAAA,wDAAY,EAACA;AAEb,IAAIK,IAAIL,SAAS,8BAAYM,GAAG"}}]
}
@@ -11,6 +11,13 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbo
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log(__TURBOPACK__import$2e$meta__.url);
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/index.js"],"sourcesContent":["import './mod.cjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 10, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs"],"sourcesContent":["console.log(import.meta.url);\n"],"names":["console","log","url"],"mappings":";;;;;AAAAA,QAAQC,GAAG,CAAC,8BAAYC,GAAG"}}]
{"offset": {"line": 10, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs"],"sourcesContent":["console.log(import.meta.url);\n"],"names":["console","log","url"],"mappings":";;;;;;;;;;;;AAAAA,QAAQC,GAAG,CAAC,8BAAYC,GAAG"}}]
}
@@ -13,6 +13,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
function foo() {
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/index.js"],"sourcesContent":["import './mod.mjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs"],"sourcesContent":["function foo() {\n console.log(import.meta.url)\n}\nfunction bar() {\n console.log(import.meta.url)\n}\n\nfoo()\nbar()\n"],"names":["foo","console","log","url","bar"],"mappings":";;;;;;AAAA,SAASA;IACPC,QAAQC,GAAG,CAAC,8BAAYC,GAAG;AAC7B;AACA,SAASC;IACPH,QAAQC,GAAG,CAAC,8BAAYC,GAAG;AAC7B;AAEAH;AACAI"}}]
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs"],"sourcesContent":["function foo() {\n console.log(import.meta.url)\n}\nfunction bar() {\n console.log(import.meta.url)\n}\n\nfoo()\nbar()\n"],"names":["foo","console","log","url","bar"],"mappings":";;;;;;;;;;;;;AAAA,SAASA;IACPC,QAAQC,GAAG,CAAC,8BAAYC,GAAG;AAC7B;AACA,SAASC;IACPH,QAAQC,GAAG,CAAC,8BAAYC,GAAG;AAC7B;AAEAH;AACAI"}}]
}
@@ -13,6 +13,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
__TURBOPACK__import$2e$meta__.foo = 1;
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/index.js"],"sourcesContent":["import './mod.mjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs"],"sourcesContent":["import.meta.foo = 1\n"],"names":["foo"],"mappings":";;;;;;AAAA,8BAAYA,GAAG,GAAG"}}]
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs"],"sourcesContent":["import.meta.foo = 1\n"],"names":["foo"],"mappings":";;;;;;;;;;;;;AAAA,8BAAYA,GAAG,GAAG"}}]
}
@@ -13,6 +13,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log(__TURBOPACK__import$2e$meta__);
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/index.js"],"sourcesContent":["import './mod.mjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs"],"sourcesContent":["console.log(import.meta)\n"],"names":["console","log"],"mappings":";;;;;;AAAAA,QAAQC,GAAG"}}]
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs"],"sourcesContent":["console.log(import.meta)\n"],"names":["console","log"],"mappings":";;;;;;;;;;;;;AAAAA,QAAQC,GAAG"}}]
}
@@ -13,6 +13,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log(__TURBOPACK__import$2e$meta__.url);
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/index.js"],"sourcesContent":["import './mod.mjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs"],"sourcesContent":["console.log(import.meta.url)\n"],"names":["console","log","url"],"mappings":";;;;;;AAAAA,QAAQC,GAAG,CAAC,8BAAYC,GAAG"}}]
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs"],"sourcesContent":["console.log(import.meta.url)\n"],"names":["console","log","url"],"mappings":";;;;;;;;;;;;;AAAAA,QAAQC,GAAG,CAAC,8BAAYC,GAAG"}}]
}
@@ -16,6 +16,13 @@ __turbopack_context__.s([]);
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
const assetUrl = new __turbopack_context__.U(__turbopack_context__.r("[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/url/input/asset.txt (static in ecmascript)"));
@@ -3,5 +3,5 @@
"sources": [],
"sections": [
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/url/input/index.js"],"sourcesContent":["import './mod.mjs'\n"],"names":[],"mappings":";AAAA"}},
{"offset": {"line": 14, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs"],"sourcesContent":["const assetUrl = new URL('./asset.txt', import.meta.url)\n\nconsole.log(assetUrl)\nfetch(assetUrl)\n .then((res) => res.text())\n .then(console.log)\n"],"names":["assetUrl","console","log","fetch","then","res","text"],"mappings":";;;;;;AAAA,MAAMA;AAENC,QAAQC,GAAG,CAACF;AACZG,MAAMH,UACHI,IAAI,CAAC,CAACC,MAAQA,IAAIC,IAAI,IACtBF,IAAI,CAACH,QAAQC,GAAG"}}]
{"offset": {"line": 14, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs"],"sourcesContent":["const assetUrl = new URL('./asset.txt', import.meta.url)\n\nconsole.log(assetUrl)\nfetch(assetUrl)\n .then((res) => res.text())\n .then(console.log)\n"],"names":["assetUrl","console","log","fetch","then","res","text"],"mappings":";;;;;;;;;;;;;AAAA,MAAMA;AAENC,QAAQC,GAAG,CAACF;AACZG,MAAMH,UACHI,IAAI,CAAC,CAACC,MAAQA,IAAIC,IAAI,IACtBF,IAAI,CAACH,QAAQC,GAAG"}}]
}
@@ -12,6 +12,13 @@ __turbopack_context__.s([
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
__turbopack_context__.A("[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/vercel.mjs [test] (ecmascript, async loader)").then(console.log);
@@ -4,6 +4,13 @@
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/workers/basic/input/index.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
console.log('index.js');
File diff suppressed because one or more lines are too long
@@ -4,6 +4,13 @@
var __TURBOPACK__import$2e$meta__ = {
get url () {
return __turbopack_context__.F("turbopack/crates/turbopack-tests/tests/snapshot/workers/shared/input/index.js");
},
env: {
DEV: true,
PROD: false,
MODE: "development",
BASE_URL: "/",
SSR: false
}
};
const url = new __turbopack_context__.U(__turbopack_context__.r("[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/shared/input/worker.js (static in ecmascript)"));
File diff suppressed because one or more lines are too long