Skip to content

Commit

Permalink
Revert "feat(next-core): support unsupported module runtime error (#6…
Browse files Browse the repository at this point in the history
…3491)" (#63575)

### What?

It's causing `__import_unsupported` is not defined in `instrumentation`
context
  • Loading branch information
sokra committed Mar 21, 2024
1 parent abe74a5 commit 7d95336
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 164 deletions.
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/next_edge/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod context;
pub mod entry;
pub mod route_regex;
pub mod unsupported;
77 changes: 0 additions & 77 deletions packages/next-swc/crates/next-core/src/next_edge/unsupported.rs

This file was deleted.

72 changes: 0 additions & 72 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::{
mode::NextMode,
next_client::context::ClientContextType,
next_config::NextConfig,
next_edge::unsupported::NextEdgeUnsupportedModuleReplacer,
next_font::{
google::{
NextFontGoogleCssModuleReplacer, NextFontGoogleFontFileReplacer, NextFontGoogleReplacer,
Expand All @@ -39,57 +38,6 @@ use crate::{
util::NextRuntime,
};

const NODE_INTERNALS: [&str; 48] = [
"assert",
"async_hooks",
"child_process",
"cluster",
"console",
"constants",
"dgram",
"diagnostics_channel",
"dns",
"dns/promises",
"domain",
"events",
"fs",
"fs/promises",
"http",
"http2",
"https",
"inspector",
"module",
"net",
"os",
"path",
"path/posix",
"path/win32",
"perf_hooks",
"process",
"punycode",
"querystring",
"readline",
"repl",
"stream",
"stream/promises",
"stream/web",
"string_decoder",
"sys",
"timers",
"timers/promises",
"tls",
"trace_events",
"tty",
"util",
"util/types",
"v8",
"vm",
"wasi",
"worker_threads",
"zlib",
"pnpapi",
];

// Make sure to not add any external requests here.
/// Computes the Next-specific client import map.
#[turbo_tasks::function]
Expand Down Expand Up @@ -468,29 +416,9 @@ pub async fn get_next_edge_import_map(
)
.await?;

insert_unsupported_node_internal_aliases(&mut import_map, project_path, execution_context);

Ok(import_map.cell())
}

/// Insert default aliases for the node.js's internal to raise unsupported
/// runtime errors. User may provide polyfills for their own by setting user
/// config's alias.
fn insert_unsupported_node_internal_aliases(
import_map: &mut ImportMap,
project_path: Vc<FileSystemPath>,
execution_context: Vc<ExecutionContext>,
) {
let unsupported_replacer = ImportMapping::Dynamic(Vc::upcast(
NextEdgeUnsupportedModuleReplacer::new(project_path, execution_context),
))
.into();

NODE_INTERNALS.iter().for_each(|module| {
import_map.insert_alias(AliasPattern::exact(*module), unsupported_replacer);
});
}

pub fn get_next_client_resolved_map(
_context: Vc<FileSystemPath>,
_root: Vc<FileSystemPath>,
Expand Down
5 changes: 1 addition & 4 deletions test/integration/edge-runtime-module-errors/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ export function expectUnsupportedModuleDevError(
output = context.logs.output
) {
expectUnsupportedModuleProdError(moduleName, output)
// turbopack have correct error overly, but doesn't emit those into cli
if (!process.env.TURBOPACK) {
expect(stripAnsi(output)).toContain(importStatement)
}
expect(stripAnsi(output)).toContain(importStatement)

const moduleNotSupportedMessage = getUnsupportedModule(moduleName)
expect(responseText).toContain(escapeLF(moduleNotSupportedMessage))
Expand Down
24 changes: 14 additions & 10 deletions test/turbopack-dev-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9531,17 +9531,21 @@
"test/integration/edge-runtime-module-errors/test/index.test.js": {
"passed": [
"Edge runtime code with imports Edge API importing vanilla 3rd party module does not throw in dev at runtime",
"Edge runtime code with imports Edge API using Buffer polyfill does not throw in dev at runtime",
"Edge runtime code with imports Middleware importing vanilla 3rd party module does not throw in dev at runtime",
"Edge runtime code with imports Edge API dynamically importing node.js module development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Edge API dynamically importing node.js module in a lib development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module in a lib development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Edge API using Buffer polyfill does not throw in dev at runtime",
"Edge runtime code with imports Middleware using Buffer polyfill does not throw in dev at runtime",
"Edge runtime code with imports Edge API statically importing 3rd party module throws not-found module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware statically importing 3rd party module throws not-found module error in dev at runtime and highlights the faulty line"
],
"failed": [],
"failed": [
"Edge runtime code with imports Edge API dynamically importing node.js module development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Edge API dynamically importing node.js module in a lib development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module in a lib development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module development mode throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing node.js module in a lib development mode throws unsupported module error in dev at runtime and highlights the faulty line"
],
"pending": [
"Edge runtime code with imports Edge API dynamically importing node.js module in a lib production mode throws unsupported module error in production at runtime and prints error on logs",
"Edge runtime code with imports Edge API dynamically importing node.js module production mode throws unsupported module error in production at runtime and prints error on logs",
Expand All @@ -9559,16 +9563,16 @@
},
"test/integration/edge-runtime-module-errors/test/module-imports.test.js": {
"passed": [
"Edge runtime code with imports Edge API importing unused node.js module does not throw in dev at runtime",
"Edge runtime code with imports Middleware importing unused node.js module does not throw in dev at runtime",
"Edge runtime code with imports Edge API statically importing node.js module throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware statically importing node.js module throws unsupported module error in dev at runtime and highlights the faulty line"
"Edge runtime code with imports Edge API importing unused node.js module does not throw in dev at runtime"
],
"failed": [
"Edge runtime code with imports Edge API dynamically importing 3rd party module throws not-found module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Edge API importing unused 3rd party module throws not-found module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Edge API statically importing node.js module throws unsupported module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware dynamically importing 3rd party module throws not-found module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware importing unused 3rd party module throws not-found module error in dev at runtime and highlights the faulty line"
"Edge runtime code with imports Middleware importing unused 3rd party module throws not-found module error in dev at runtime and highlights the faulty line",
"Edge runtime code with imports Middleware importing unused node.js module does not throw in dev at runtime",
"Edge runtime code with imports Middleware statically importing node.js module throws unsupported module error in dev at runtime and highlights the faulty line"
],
"pending": [
"Edge runtime code with imports Edge API dynamically importing 3rd party module production mode does not build and reports module not found error",
Expand Down

0 comments on commit 7d95336

Please sign in to comment.