Browse Source

better error for missing export (#1033)

legacy-quote-reserved-properties
Rich-Harris 8 years ago
parent
commit
78515c3fb1
  1. 3
      src/Module.js
  2. 4
      src/utils/relativeId.js
  3. 2
      test/function/import-of-unexported-fails/_config.js
  4. 2
      test/test.js

3
src/Module.js

@ -6,6 +6,7 @@ import { basename, extname } from './utils/path.js';
import getLocation from './utils/getLocation.js'; import getLocation from './utils/getLocation.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js'; import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import relativeId from './utils/relativeId.js';
import { SyntheticNamespaceDeclaration } from './Declaration.js'; import { SyntheticNamespaceDeclaration } from './Declaration.js';
import extractNames from './ast/utils/extractNames.js'; import extractNames from './ast/utils/extractNames.js';
import enhance from './ast/enhance.js'; import enhance from './ast/enhance.js';
@ -357,7 +358,7 @@ export default class Module {
const declaration = otherModule.traceExport( importDeclaration.name ); const declaration = otherModule.traceExport( importDeclaration.name );
if ( !declaration ) throw new Error( `Module ${otherModule.id} does not export ${importDeclaration.name} (imported by ${this.id})` ); if ( !declaration ) throw new Error( `'${importDeclaration.name}' is not exported by ${relativeId( otherModule.id )} (imported by ${relativeId( this.id )}). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` );
return declaration; return declaration;
} }

4
src/utils/relativeId.js

@ -0,0 +1,4 @@
export default function relativeId ( id ) {
if ( typeof process === 'undefined' ) return id;
return id.replace( process.cwd(), '' ).replace( /^[\/\\]/, '' );
}

2
test/function/import-of-unexported-fails/_config.js

@ -3,6 +3,6 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'marking an imported, but unexported, identifier should throw', description: 'marking an imported, but unexported, identifier should throw',
error: function ( err ) { error: function ( err ) {
assert.ok( /Module .+empty\.js does not export default \(imported by .+main\.js\)/.test( err.message ) ); assert.equal( err.message, `'default' is not exported by empty.js (imported by main.js). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` );
} }
}; };

2
test/test.js

@ -186,6 +186,8 @@ describe( 'rollup', function () {
const config = loadConfig( FUNCTION + '/' + dir + '/_config.js' ); const config = loadConfig( FUNCTION + '/' + dir + '/_config.js' );
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => { ( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
process.chdir( FUNCTION + '/' + dir );
const warnings = []; const warnings = [];
const captureWarning = msg => warnings.push( msg ); const captureWarning = msg => warnings.push( msg );

Loading…
Cancel
Save