Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Use legacy module missing code “MODULE_NOT_FOUND” for cjs. [closes #206]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 3, 2018
1 parent ce81a9b commit 96d4ca4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/module/cjs/_resolve-filename.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _resolveFilename from "../_resolve-filename.js"
import errors from "../../errors.js"
import getModuleName from "../../util/get-module-name.js"
import shared from "../../shared.js"
import toStringLiteral from "../../util/to-string-literal.js"

function resolveFilename(id, parent, isMain) {
const cacheKey = id + "\0" + getModuleName(parent) + "\0" + isMain
Expand All @@ -16,7 +16,9 @@ function resolveFilename(id, parent, isMain) {
return shared.resolveFilename[cacheKey] = filePath
}

throw new errors.Error("ERR_MISSING_MODULE", id)
const error = new Error("Cannot find module '" + toStringLiteral(id) + "'")
error.code = "MODULE_NOT_FOUND"
throw error
}

export default resolveFilename
9 changes: 8 additions & 1 deletion test/main-hook-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ describe("module.runMain hook", function () {
.reduce((promise, args) =>
promise
.then(() => node(args))
.then((result) => assert.ok(result.stderr.includes("ERR_MISSING_MODULE")))
.then((result) => {
const fileName = args[2]
const code = fileName.endsWith(".mjs")
? "ERR_MISSING_MODULE"
: "MODULE_NOT_FOUND"

assert.ok(result.stderr.includes(code))
})
, Promise.resolve())
})
})

0 comments on commit 96d4ca4

Please sign in to comment.