From da1d68ba1e2cf007c80c67edef13283b4d228796 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 11 Jan 2019 20:22:25 +0100 Subject: [PATCH] warn with the importer in case of missing module --- ext/npm-extension.js | 9 +++++--- steal.production.js | 2 +- test/npm_nested_import_errors/dev.html | 24 ++++++++++++++++++++++ test/npm_nested_import_errors/main.js | 2 ++ test/npm_nested_import_errors/package.json | 8 ++++++++ test/test.js | 6 +++++- 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/npm_nested_import_errors/dev.html create mode 100644 test/npm_nested_import_errors/main.js create mode 100644 test/npm_nested_import_errors/package.json diff --git a/ext/npm-extension.js b/ext/npm-extension.js index 402612e82..fb180d0a2 100644 --- a/ext/npm-extension.js +++ b/ext/npm-extension.js @@ -393,11 +393,14 @@ exports.addExtension = function addNpmExtension(System){ if ((statusCode === 404 || statusCode === 0) && utils.moduleName.isBareIdentifier(load.name) && !utils.pkg.isRoot(loader, load.metadata.npmPackage)) { - var newError = new Error([ - "Could not load '" + load.name + "'", + var errorMsg = ["Could not load '" + load.name + "'", "Is this an npm module not saved in your package.json?" - ].join("\n")); + ].join("\n"); + var newError = new Error(); newError.statusCode = error.statusCode; + newError.stack = newError.stack + error.stack; + newError.message = errorMsg; + throw newError; } else { throw error; diff --git a/steal.production.js b/steal.production.js index 6c2b91bd7..4055a15e4 100644 --- a/steal.production.js +++ b/steal.production.js @@ -1,5 +1,5 @@ /* - * steal v2.1.12 + * steal v2.1.13 * * Copyright (c) 2019 Bitovi; Licensed MIT */ diff --git a/test/npm_nested_import_errors/dev.html b/test/npm_nested_import_errors/dev.html new file mode 100644 index 000000000..b46769968 --- /dev/null +++ b/test/npm_nested_import_errors/dev.html @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/npm_nested_import_errors/main.js b/test/npm_nested_import_errors/main.js new file mode 100644 index 000000000..f05e24d00 --- /dev/null +++ b/test/npm_nested_import_errors/main.js @@ -0,0 +1,2 @@ +//require("dep"); +console.log("Imported"); \ No newline at end of file diff --git a/test/npm_nested_import_errors/package.json b/test/npm_nested_import_errors/package.json new file mode 100644 index 000000000..f7e91e25d --- /dev/null +++ b/test/npm_nested_import_errors/package.json @@ -0,0 +1,8 @@ +{ + "name": "npm_nested_import_errors", + "main": "main.js", + "version": "1.0.0", + "dependencies": { + "dep": "1.0.0" + } +} diff --git a/test/test.js b/test/test.js index 57f7ccef0..19a79637e 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ var QUnit = require("steal-qunit"); QUnit.config.testTimeout = 30000; -require("src/cache-bust/test/"); +// require("src/cache-bust/test/"); require("src/env/test/"); require("src/json/test/"); require("src/trace/trace_test"); @@ -477,3 +477,7 @@ QUnit.test("dev bundle loads BEFORE configMain", function(assert) { QUnit.test("When the dev-bundle is missing we get a nice message", function(assert){ makeIframe("dev_bundle_err/dev.html", assert); }); + +QUnit.test("If a package is missing, warn which file imported it #1463", function(assert) { + makeIframe("npm_nested_import_errors/dev.html", assert); +}) \ No newline at end of file