react-monocle icon indicating copy to clipboard operation
react-monocle copied to clipboard

TypeError: Cannot read property 'name' of null

Open jbe456 opened this issue 8 years ago • 3 comments

When I run the following command:

monocle -c index.html -b scripts/index.js

I have this error:

Starting to strip comments from bundle file...
Took 0.508 seconds to strip comments input bundle file
C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:43
      } else if (node.declaration.name || node.declaration.id.name) {
                                                             ^

TypeError: Cannot read property 'name' of null
    at ast.body.forEach (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:43:62)
    at Array.forEach (native)
    at astGenerator (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:35:12)
    at files.map.ele (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\bin\cmd.js:51:35)
    at Array.map (native)
    at glob (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\bin\cmd.js:51:24)
    at f (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\node_modules\once\once.js:17:25)
    at Glob.<anonymous> (C:\Users\XXX\AppData\Roaming\npm\node_modules\react-monocle\node_modules\glob\glob.js:147:7)
    at emitOne (events.js:96:13)
    at Glob.emit (events.js:188:7)

The file is bundle with webpack, non minimified, split into two chunks (I'm doing it in the main chunk).

I can't provide the original file so when I'll have time I'll try to reproduce it on a smaller javascript set and I'll update the post. I thought it would be good to post it if somebody had the same issue meanwhile.

jbe456 avatar Jul 27 '16 19:07 jbe456

Hey, thanks for the feedback! I think what's happening is that it's choking on an export default (which we use to determine names of stateless functional components). Could you send me how you're using it (either on here or a private message works) and we'll try and fix/cover the issue!

jerrymao15 avatar Jul 27 '16 23:07 jerrymao15

I've run into the same problem:

{ my-account-ui } master » monocle -b my-account.js -j js -e app/index.js                                                                                                                     /c/Users/SCHEJL01/Projects/my-account-ui 130
Starting to strip comments from bundle file...
Took 6.374 seconds to strip comments input bundle file
C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:43
      } else if (node.declaration.name || node.declaration.id.name) {
                                                             ^

TypeError: Cannot read property 'name' of undefined
    at C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:43:62
    at Array.forEach (native)
    at astGenerator (C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\src\astGenerator.js:35:12)
    at C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\bin\cmd.js:52:35
    at Array.map (native)
    at C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\bin\cmd.js:52:24
    at f (C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\node_modules\once\once.js:25:25)
    at Glob.<anonymous> (C:\Users\SCHEJL01\AppData\Roaming\npm\node_modules\react-monocle\node_modules\glob\glob.js:151:7)
    at emitOne (events.js:77:13)
    at Glob.emit (events.js:169:7)

I will send more information but I'm not sure what do you exactly mean by "Could you send me how you're using it"

bicz avatar Sep 09 '16 13:09 bicz

I was seeing this issue with a stateless functional component being exported directly, e.g.

export default props => {
  // rendering code
}

Changing to the following allowed some forward progress (although I have still not gotten monocle running on my code base yet):

const MyComponent = props => {
  // rendering code
}

export default MyComponent

Hope that helps someone!

shipstar avatar Oct 15 '16 12:10 shipstar