Skip to content

Commit

Permalink
warn with the importer in case of missing module
Browse files Browse the repository at this point in the history
  • Loading branch information
cherifGsoul committed Jan 11, 2019
1 parent 8c81c5a commit da1d68b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
9 changes: 6 additions & 3 deletions ext/npm-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion steal.production.js

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

24 changes: 24 additions & 0 deletions test/npm_nested_import_errors/dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
window.done = window.parent.done;
window.assert = window.parent.assert;
</script>
<script src="../../steal-with-promises.js" main="@empty"
config="package.json!npm"
src="../../../steal-with-promises.js">
System.import('dep').then(null, function(err){
if(window.assert) {
var stack = err.stack;
window.assert.ok(/dep.js/.test(stack), "dep.js is in the stack");
window.done();
}
});
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions test/npm_nested_import_errors/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//require("dep");
console.log("Imported");
8 changes: 8 additions & 0 deletions test/npm_nested_import_errors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "npm_nested_import_errors",
"main": "main.js",
"version": "1.0.0",
"dependencies": {
"dep": "1.0.0"
}
}
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
})

0 comments on commit da1d68b

Please sign in to comment.