Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts

packages/next-env/**/*.d.ts
**/next-env.d.ts

test/**/out/**
test/development/basic/hmr/components/parse-error.js
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use turbopack_core::{
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference::all_assets_from_entries,
reference_type::{CommonJsReferenceSubType, CssReferenceSubType, ReferenceType},
resolve::{origin::PlainResolveOrigin, parse::Request, pattern::Pattern},
resolve::{ResolveErrorMode, origin::PlainResolveOrigin, parse::Request, pattern::Pattern},
source::Source,
source_map::SourceMapAsset,
virtual_output::VirtualOutputAsset,
Expand Down Expand Up @@ -840,7 +840,7 @@ impl AppProject {
))),
CommonJsReferenceSubType::Undefined,
None,
false,
ResolveErrorMode::Error,
)
.resolve()
.await?
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/next_server_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use turbopack_core::{
file_source::FileSource,
output::{OutputAsset, OutputAssets, OutputAssetsReference},
reference_type::{CommonJsReferenceSubType, ReferenceType},
resolve::{origin::PlainResolveOrigin, parse::Request},
resolve::{ResolveErrorMode, origin::PlainResolveOrigin, parse::Request},
traced_asset::TracedAsset,
};
use turbopack_resolve::ecmascript::cjs_resolve;
Expand Down Expand Up @@ -245,7 +245,7 @@ impl ServerNftJsonAsset {
Request::parse_string(path.into()),
CommonJsReferenceSubType::Undefined,
None,
false,
ResolveErrorMode::Error,
)
.primary_modules()
.await?
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use turbopack_core::{
output::{OptionOutputAsset, OutputAsset, OutputAssets},
reference::all_assets_from_entries,
reference_type::{EcmaScriptModulesReferenceSubType, EntryReferenceSubType, ReferenceType},
resolve::{origin::PlainResolveOrigin, parse::Request, pattern::Pattern},
resolve::{ResolveErrorMode, origin::PlainResolveOrigin, parse::Request, pattern::Pattern},
source::Source,
virtual_output::VirtualOutputAsset,
};
Expand Down Expand Up @@ -562,7 +562,7 @@ impl PagesProject {
},
)),
EcmaScriptModulesReferenceSubType::Undefined,
false,
ResolveErrorMode::Error,
None,
)
.await?
Expand Down
4 changes: 3 additions & 1 deletion crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ async fn build_manifest(
&key,
ActionManifestWorkerEntry {
module_id: loader_id.clone(),
is_async: *async_module_info.is_async(chunk_item.module()).await?,
is_async: async_module_info
.is_async(chunk_item.module().to_resolved().await?)
.await?,
exported_name: name.as_str(),
filename: filename.as_str(),
},
Expand Down
1 change: 1 addition & 0 deletions crates/next-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
smallvec = { workspace = true }
swc_sourcemap = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_client/runtime_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use turbopack_core::{
context::AssetContext,
module::Module,
reference_type::CommonJsReferenceSubType,
resolve::{origin::PlainResolveOrigin, parse::Request},
resolve::{ResolveErrorMode, origin::PlainResolveOrigin, parse::Request},
source::Source,
};
use turbopack_resolve::ecmascript::cjs_resolve;
Expand Down Expand Up @@ -38,7 +38,7 @@ impl RuntimeEntry {
*request,
CommonJsReferenceSubType::Undefined,
None,
false,
ResolveErrorMode::Error,
)
.resolve()
.await?
Expand Down
27 changes: 14 additions & 13 deletions crates/next-core/src/next_manifests/client_reference_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,21 @@ async fn build_manifest(
.try_flat_join()
.await?;

let async_modules = async_module_info
.is_async_multiple(Vc::cell(
client_references_ecmascript
.iter()
.flat_map(|(r, r_val)| {
[
ResolvedVc::upcast(*r),
ResolvedVc::upcast(r_val.client_module),
ResolvedVc::upcast(r_val.ssr_module),
]
let async_modules = client_references_ecmascript
.iter()
.flat_map(|(r, r_val)| {
[
ResolvedVc::upcast(*r),
ResolvedVc::upcast(r_val.client_module),
ResolvedVc::upcast(r_val.ssr_module),
]
}).map(async move |asset| {
Ok(if async_module_info.is_async(asset).await? {
Some(asset)
} else {
None
})
.collect(),
))
.await?;
}).try_flat_join().await?;

async fn cached_chunk_paths(
cache: &mut FxHashMap<ResolvedVc<Box<dyn OutputAsset>>, FileSystemPath>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub async fn get_swc_ecma_transform_rule_impl(
asset::Asset,
module::Module,
reference_type::{CommonJsReferenceSubType, ReferenceType},
resolve::{handle_resolve_error, parse::Request, resolve},
resolve::{ResolveErrorMode, handle_resolve_error, parse::Request, resolve},
};
use turbopack_ecmascript_plugins::transform::swc_ecma_transform_plugins::{
SwcEcmaTransformPluginsTransformer, SwcPluginModule,
Expand Down Expand Up @@ -120,7 +120,7 @@ pub async fn get_swc_ecma_transform_rule_impl(
Vc::upcast(DummyResolveOrigin::new(project_path.clone())),
request,
resolve_options,
false,
ResolveErrorMode::Error,
// TODO proper error location
None,
)
Expand Down
31 changes: 11 additions & 20 deletions crates/next-core/src/raw_ecmascript_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::Write;
use anyhow::{Result, bail};
use once_cell::sync::Lazy;
use regex::Regex;
use smallvec::smallvec;
use tracing::Instrument;
use turbo_rcstr::rcstr;
use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
Expand All @@ -13,7 +14,8 @@ use turbopack_core::{
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext},
code_builder::CodeBuilder,
compile_time_info::{
CompileTimeDefineValue, CompileTimeInfo, DefinableNameSegment, FreeVarReference,
CompileTimeDefineValue, CompileTimeInfo, DefinableNameSegmentRef, DefinableNameSegmentRefs,
FreeVarReference,
},
context::AssetContext,
ident::AssetIdent,
Expand Down Expand Up @@ -193,12 +195,7 @@ impl EcmascriptChunkItem for RawEcmascriptChunkItem {

let mut code = CodeBuilder::default();
if !env_vars.is_empty() {
let replacements = module
.compile_time_info
.await?
.free_var_references
.individual()
.await?;
let replacements = module.compile_time_info.await?.free_var_references;
code += "var process = {env:\n";
writeln!(
code,
Expand All @@ -209,20 +206,14 @@ impl EcmascriptChunkItem for RawEcmascriptChunkItem {
.map(async |name| {
Ok((
name,
if let Some(value) =
replacements.get(&DefinableNameSegment::Name(name.into()))
&& let Some((_, value)) =
value.0.iter().find(|(path, _)| {
matches!(
path.as_slice(),
[
DefinableNameSegment::Name(a),
DefinableNameSegment::Name(b)
] if a == "process" && b == "env"
)
})
if let Some(value) = replacements
.get(&DefinableNameSegmentRefs(smallvec![
DefinableNameSegmentRef::Name("process"),
DefinableNameSegmentRef::Name("env"),
DefinableNameSegmentRef::Name(name),
]))
.await?
{
let value = value.await?;
let value = match &*value {
FreeVarReference::Value(
CompileTimeDefineValue::String(value),
Expand Down
42 changes: 42 additions & 0 deletions docs/01-app/02-guides/lazy-loading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,48 @@ const ClientComponent = dynamic(() =>
)
```

## Magic Comments

Next.js supports magic comments to control how dynamic imports are handled by the bundler. These comments work with dynamic `import()`, `require()`, `require.resolve()`, and `new Worker()` expressions.

> **Good to know:** Magic comments do not work with static `import` statements (`import x from 'y'`). They only work with dynamic expressions.

### `webpackIgnore` / `turbopackIgnore`

Use these comments to skip bundling a dynamic import. The import expression will be left as-is in the output, useful for runtime-only modules:

```js
// Skip bundling - import happens at runtime
const runtime = await import(/* webpackIgnore: true */ 'runtime-module')

// Turbopack-specific variant
const plugin = await import(/* turbopackIgnore: true */ pluginPath)

// Also works with require
const mod = require(/* webpackIgnore: true */ 'runtime-module')
```

### `turbopackOptional` (Turbopack only)

Use this comment to suppress build errors when a module might not exist. The import will still throw at runtime if the module is missing:

```js
// No build error if './optional-feature' doesn't exist
// Runtime will throw MODULE_NOT_FOUND if executed
const feature = await import(/* turbopackOptional: true */ './optional-feature')

// Also works with require
const mod = require(/* turbopackOptional: true */ './optional-module')
```

This is useful for:

- Conditional features that may not be installed
- Plugin systems where modules are optional
- Gradual migrations where some files may not exist yet

> **Good to know:** `webpackOptional` is not supported. Use `turbopackOptional` instead when using Turbopack.

</AppOnly>

<PagesOnly>
Expand Down
15 changes: 14 additions & 1 deletion docs/01-app/03-api-reference/08-turbopack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,20 @@ Turbopack in Next.js has **zero-configuration** for the common use cases. Below
| Feature | Status | Notes |
| ------------------------ | ------------- | ---------------------------------------------------------------------------------------- |
| **Fast Refresh** | **Supported** | Updates JavaScript, TypeScript, and CSS without a full refresh. |
| **Incremental Bundling** | **Supported** | Turbopack lazily builds only what’s requested by the dev server, speeding up large apps. |
| **Incremental Bundling** | **Supported** | Turbopack lazily builds only what's requested by the dev server, speeding up large apps. |

### Magic Comments

Turbopack supports webpack-compatible magic comments for controlling import behavior. These comments work with dynamic `import()`, `require()`, `require.resolve()`, and `new Worker()` expressions (not static `import` statements).

| Comment | Webpack | Turbopack | Description |
| ------------------------- | ------- | --------- | ------------------------------ |
| `webpackIgnore: true` | ✓ | ✓ | Skip bundling, preserve import |
| `turbopackIgnore: true` | ✗ | ✓ | Skip bundling (Turbopack-only) |
| `turbopackOptional: true` | ✗ | ✓ | Suppress resolve errors |
| `webpackOptional: true` | ✗ | ✗ | Not supported |

See [Lazy Loading](/docs/app/guides/lazy-loading#magic-comments) for usage examples.

## Known gaps with webpack

Expand Down
11 changes: 11 additions & 0 deletions packages/next/src/compiled/@hapi/accept/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) 2014-2020, Sideway Inc, and project contributors
Copyright (c) 2015-2016, Mark Bradshaw
Copyright (c) 2014, Walmart.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2018–present Artem Zakharchenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions packages/next/src/compiled/async-retry/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 ZEIT, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions packages/next/src/compiled/async-sema/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2017, 2018 Zeit, Inc.
Copyright (c) 2013 Petka Antonov (For the Deque library)


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions packages/next/src/compiled/domain-browser/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- LICENSEFILE/ -->

<h1>License</h1>

Unless stated otherwise all works are:

<ul><li>Copyright &copy; 2013+ <a href="http://bevry.me">Bevry Pty Ltd</a></li></ul>

and licensed under:

<ul><li><a href="http://spdx.org/licenses/MIT.html">MIT License</a></li></ul>

<h2>MIT License</h2>

<pre>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre>

<!-- /LICENSEFILE -->
Loading
Loading