Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'getName' of undefined #928

Closed
yairEO opened this issue Sep 12, 2016 · 21 comments · Fixed by #962
Closed

TypeError: Cannot read property 'getName' of undefined #928

yairEO opened this issue Sep 12, 2016 · 21 comments · Fixed by #962

Comments

@yairEO
Copy link

yairEO commented Sep 12, 2016

I get this error after updating to version v0.35.9 and no bundle is generated.

0.34.13 works fine.


I'm on windows 7, Node v6.3.0

@TrySound
Copy link
Member

@yairEO Can you report full stack trace?

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

@TrySound - How do I do that? I use Gulp to run Rollup in a task, and it looks like this:

gulp.task('bundleJS', function(callback) {
    var outputFileName = config.namespace + '.js',
        cache;

    rollup({
        entry   : 'js/dist/app.js',
        plugins : rollupPlugins,
        cache   : cache
    })
    .then(function (bundle) {
        var bundleSettings = {
                format    : 'umd',
            //  sourceMap : true,
                banner    : config.banner
            },
            result = bundle.generate(bundleSettings),
            mapFileName = outputFileName + '.map',
            sourceMappingURL = '\n//# sourceMappingURL='+ mapFileName;

        cache = bundle;

        // bundle file
        fs.writeFile( '../js/' + outputFileName, result.code + (bundleSettings.sourceMap ? sourceMappingURL : ''), function(){
            callback();
        });

        // map file
        if( bundleSettings.sourceMap )
            fs.writeFile( '../js/' + mapFileName, result.map.toString());
    })
    .catch(function(err){
        gutil.log( gutil.colors.white.bgRed('Rollup [catch]: ', err) );
        callback();
    })
});

the error message is generated from the catch(function(err){ function

@TrySound
Copy link
Member

console.log(err.stack);

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

C:\www\UI\BUILD>gulp bundleJS
(node:41256) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please u
pdate it to a more recent version.
(node:41256) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please u
pdate it to a more recent version.
[13:17:18] Using gulpfile C:\www\UI\BUILD\gulpfile.js
[13:17:18] Starting 'bundleJS'...
[13:17:21] Rollup [catch]:  TypeError: Cannot read property 'getName' of undefined
    at C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:7219:27
    at C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:134:57
    at Array.forEach (native)
    at forOwn (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:134:24)
    at ModuleScope.deshadow (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:7211:3)
    at C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:5346:57
    at Array.forEach (native)
    at BundleScope.deshadow (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:5346:16)
    at Bundle.deconflict (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:8645:13)
    at C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:8598:11
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:577:11)
    at run (bootstrap_node.js:352:7)
    at startup (bootstrap_node.js:144:9)
    at bootstrap_node.js:467:3
[13:17:21] Finished 'bundleJS' after 2.21 s

@Havunen
Copy link

Havunen commented Sep 13, 2016

I see the same issue with following setup: https://github.com/trueadm/inferno/blob/dev/config/rollup.config.js
(inferno - dev branch)

Updating rollup ("rollup": "^0.34.13", => "rollup": "^0.35.9") gives the same exception with OP.

Treating 'stream' as external dependency
TypeError: Cannot read property 'getName' of undefined
    at /media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:7219:27
    at /media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:134:57
    at Array.forEach (native)
    at forOwn (/media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:134:24)
    at ModuleScope.deshadow (/media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:7211:3)
    at /media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:5346:57
    at Array.forEach (native)
    at BundleScope.deshadow (/media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:5346:16)
    at Bundle.deconflict (/media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:8645:13)
    at /media/sk/ssd-data/GIT/inferno/node_modules/rollup/dist/rollup.js:8598:11

> inferno-src@1.0.0-alpha8 build:prod /media/sk/ssd-data/GIT/inferno
> cross-env NODE_ENV=production babel-node --presets es2015 config/rollup.config.js

Ubuntu 16.04 LTS + Node 6.5

@TrySound
Copy link
Member

@yairEO By the way you may return promise in gulp tasks to keep them in sync.

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

Thanks Bogdan, I didn't know that. I use runSequence..

@TrySound
Copy link
Member

I meant returning promise like stream instead of calling callback.
Also can you produce some failed code?

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

Yes I understood you meant that..
but what do you mean about failed code? you want me to paste the stack trace of a bad source files for rollup build?

@TrySound
Copy link
Member

@yairEO Just something minimal which causes this error.

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

Ok, I will do it tomorrow. did you test it on windows / linux yourself? maybe it will show it also with an empty entry file..

@TrySound
Copy link
Member

We have tones of tests. This is a specific case.

@yairEO
Copy link
Author

yairEO commented Sep 13, 2016

but tests done on one kind of OS and with the the latest Node version or different versions?
there are so many scenarios of setups out there, tests can only expose some of the issues I guess..

@TrySound
Copy link
Member

Our code in most cases is not os specific. The problem could be only with paths. But they was fixed some time ago.

@aubergene
Copy link

I'm getting what looks like the same error with on OSX, rollup version 0.35.10

Cannot read property 'getName' of undefined
TypeError: Cannot read property 'getName' of undefined
    at /usr/local/lib/node_modules/rollup/src/ast/scopes/ModuleScope.js:27:29
    at /usr/local/lib/node_modules/rollup/src/utils/object.js:8:40
    at Array.forEach (native)
    at forOwn (/usr/local/lib/node_modules/rollup/src/utils/object.js:8:24)
    at ModuleScope.deshadow (/usr/local/lib/node_modules/rollup/src/ast/scopes/ModuleScope.js:19:3)
    at /usr/local/lib/node_modules/rollup/src/ast/scopes/Scope.js:87:41
    at Array.forEach (native)
    at BundleScope.deshadow (/usr/local/lib/node_modules/rollup/src/ast/scopes/Scope.js:87:17)
    at Bundle.deconflict (/usr/local/lib/node_modules/rollup/src/Bundle.js:213:14)
    at /usr/local/lib/node_modules/rollup/src/Bundle.js:166:10
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki

here's my config

import node from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';

export default {
  entry: 'src/js/simple/index.js',
  plugins: [
    node({
      jsnext: true,
      // skip: [ 'd3' ],
    }),
    // uglify()
  ],
  // external: [
  //   'd3'
  // ],
  // globals: {
  //   d3: 'd3'
  // },
  moduleName: 'simpleCharts',
  sourceMap: true,
  targets: [
    { dest: 'public/js/simpleCharts.js', format: 'iife' }
  ]
}

@larrybotha
Copy link

larrybotha commented Sep 18, 2016

I thought I was going crazy... how can Rollup just work for everyone else and not me?!

v0.35.12 throws the getName reference error, 0.34.13 works fine.

OSX El Capitan (if that even matters).

Minimal test case:

// gulp task
const gulp        = require('gulp');
const rollup      = require('rollup').rollup;
const commonJs    = require('rollup-plugin-commonjs');
const buble       = require('rollup-plugin-buble');
const babel       = require('rollup-plugin-babel');
const resolve     = require('rollup-plugin-node-resolve');

gulp.task('scripts', () => {
  return rollup({
    entry: 'src/index.js',
    plugins: [
      buble(), // or babel...
      // babel({
      //   babelrc: false,
      //   exclude: 'node_modules/**',
      //   presets: [ 'es2015-rollup', 'stage-0', 'react' ]
      // }),
      commonJs({
        include: [ 'node_modules/**' ]
      }),
      resolve()
    ],
  }).then(bundle => {
    return bundle.write({
      format: 'iife',
      dest: 'dist/app.bundle.js',
    });
  })
});
// src/index.js
import React from 'react';
import { render } from 'react-dom';

@yairEO
Copy link
Author

yairEO commented Sep 18, 2016

Should this (big) bug be assigned to anyone?
should it be labeled?

@Rich-Harris
Copy link
Contributor

Looks like this is caused by import { nonexistent } from './whatever.js' – since there's no declaration corresponding with nonexistent, declaration.getName is an error.

Folks, some friendly advice on filing bugs: you will get a response much quicker if you can supply a minimal reproduction that we can investigate. Piecing things together from the scraps of evidence in this thread is very hard. 'Minimal' means no plugins (unless they're the source of the bug), and no Gulp nonsense. It's one thing for me to spend my free weekend time on this stuff, but when it turns out to be essentially user error I hope you can understand why I'm a little frustrated!

#962 fixes this error and gives you a helpful warning.

@Havunen I get the following warning with Inferno:

Non-existent export 'hookTypes' is imported from /path/to/inferno/src/DOM/addAttributes.js by /path/to/inferno/src/DOM/shapes/rootNodeWithComponent.js

I can't find the corresponding files in the repo (some TypeScript thing I don't understand?) but if you remove hookTypes, you're golden.

@larrybotha You'll need to manually tell rollup-plugin-commonjs that react-dom exports render using the namedExports option – it can't automatically infer it from the code (because it's just re-exporting another module). See here for more info.

@aubergene, @yairEO, afraid I can't know how to fix your cases from here, but if you use the version of Rollup I'm about to release, it will tell you.

Rich-Harris added a commit that referenced this issue Sep 18, 2016
warn on missing unused imports in deshadowing phase, rather than throwing
@Havunen
Copy link

Havunen commented Sep 18, 2016

@Rich-Harris thanks from your input and hard work. Maybe you can change this exception to something more user friendly? This exception just looks like something related to rollup and googling it shows up this thread. Just thought its related. Thanks for help :)

@Rich-Harris
Copy link
Contributor

@Havunen As of 0.35.15 (just released) you'll get the warning message above, identifying the non-existent export – no error

@hzlmn
Copy link

hzlmn commented Jan 25, 2017

@Rich-Harris Hi, I get same issue with latest rollup, when import { Whatever } from './lib' is not defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants