Skip to content

Commit a723ff1

Browse files
fix relative import
1 parent a22101b commit a723ff1

File tree

1 file changed

+8
-4
lines changed
  • packages/next-swc/crates/next-core/src

1 file changed

+8
-4
lines changed

packages/next-swc/crates/next-core/src/util.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,21 @@ pub async fn load_next_js_template(
420420
.get_relative_path_to(&imported)
421421
.context("path has to be relative to package root")?;
422422

423-
if !relative.starts_with("next/") {
423+
if !relative.starts_with("./next/") {
424424
bail!(
425-
"Invariant: Expected relative import to start with \"next/\", found \"{}\"",
425+
"Invariant: Expected relative import to start with \"./next/\", found \"{}\"",
426426
relative
427427
)
428428
}
429429

430+
let relative = relative
431+
.strip_prefix("./")
432+
.context("should be able to strip the prefix")?;
433+
430434
Ok(if is_from_request {
431-
format!("from {}", StringifyJs(&relative))
435+
format!("from {}", StringifyJs(relative))
432436
} else {
433-
format!("import {}", StringifyJs(&relative))
437+
format!("import {}", StringifyJs(relative))
434438
})
435439
})
436440
.context("replacing imports failed")?;

0 commit comments

Comments
 (0)