Skip to content

Conversation

@whitneyit
Copy link

When trying to clean my code I run into the following error:

TypeError: Cannot read property 'start' of undefined
at Object.convertDefinesAndRequires ($PWD/node_modules/amdclean/src/amdclean.js:981:64)
at Controller.estraverse.replace.enter ($PWD/node_modules/amdclean/src/amdclean.js:1218:40)
at Controller.__execute ($PWD/node_modules/estraverse/estraverse.js:399:31)
at Controller.replace ($PWD/node_modules/estraverse/estraverse.js:633:27)
at Object.replace ($PWD/node_modules/estraverse/estraverse.js:714:27)
at Object.traverseAndUpdateAst ($PWD/node_modules/amdclean/src/amdclean.js:1197:14)
at Object.clean ($PWD/node_modules/amdclean/src/amdclean.js:1271:30)
at publicAPI.clean ($PWD/node_modules/amdclean/src/amdclean.js:1667:91)
at DestroyableTransform._transform ($PWD/index.js:39:26)
at DestroyableTransform.Transform._read ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
at CompileStream.ondata (_stream_readable.js:528:20)
at emitOne (events.js:77:13)

I found by hardening the check of convertDefinesAndRequires with the
code in this PR prevents this error from being thrown.

When trying to clean my code I run into the following error:

> TypeError: Cannot read property 'start' of undefined
>     at Object.convertDefinesAndRequires ($PWD/node_modules/amdclean/src/amdclean.js:981:64)
>     at Controller.estraverse.replace.enter ($PWD/node_modules/amdclean/src/amdclean.js:1218:40)
>     at Controller.__execute ($PWD/node_modules/estraverse/estraverse.js:399:31)
>     at Controller.replace ($PWD/node_modules/estraverse/estraverse.js:633:27)
>     at Object.replace ($PWD/node_modules/estraverse/estraverse.js:714:27)
>     at Object.traverseAndUpdateAst ($PWD/node_modules/amdclean/src/amdclean.js:1197:14)
>     at Object.clean ($PWD/node_modules/amdclean/src/amdclean.js:1271:30)
>     at publicAPI.clean ($PWD/node_modules/amdclean/src/amdclean.js:1667:91)
>     at DestroyableTransform._transform ($PWD/index.js:39:26)
>     at DestroyableTransform.Transform._read ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
>     at DestroyableTransform.Transform._write ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
>     at doWrite ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
>     at writeOrBuffer ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
>     at DestroyableTransform.Writable.write ($PWD/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
>     at CompileStream.ondata (_stream_readable.js:528:20)
>     at emitOne (events.js:77:13)

I found by hardening the check of `convertDefinesAndRequires` with the
code in this PR prevents this error from being thrown.
@danielbodart
Copy link

I had the same error when using AMDClean on a Typescript bundle. Here is my single line version of the above:

startLineNumber = (isDefine || isRequire) && node && node.expression && node.expression.loc && node.expression.loc.start ? node.expression.loc.start.line : node && node.loc && node.loc.start ? node.loc.start.line : null;

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 this pull request may close these issues.

2 participants