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

Don't use path.replaceWith() with a source string, use path.replaceWithSourceString() #576

Closed
INRIX-Xiaodi-Huang opened this issue Jun 13, 2017 · 31 comments
Labels
bug Confirmed bug

Comments

@INRIX-Xiaodi-Huang
Copy link

ERROR in unknown: Don't use path.replaceWith() with a source string, use path.replaceWithSourceString()

Seems to be the result of this change :
https://github.com/babel/babili/pull/543/files

@boopathi
Copy link
Member

Thanks. Do you have a small snippet as input to reproduce this ?

@boopathi boopathi added the bug Confirmed bug label Jun 13, 2017
@INRIX-Xiaodi-Huang
Copy link
Author

INRIX-Xiaodi-Huang commented Jun 13, 2017

Our codebase is pretty large. I am not sure what caused this error when minifying. I was using the babili webpack plugin with the following options.

(isProdFlavor = true);

new BabiliPlugin({
  booleans: isProdFlavor,
  builtIns: isProdFlavor,
  consecutiveAdds: isProdFlavor,
  flipComparisons: isProdFlavor,
  infinity: isProdFlavor,
   mangle: isProdFlavor,
   memberExpressions: isProdFlavor,
  mergeVars: isProdFlavor,
  numericLiterals: isProdFlavor,
  propertyLiterals: isProdFlavor,
  regexpConstructors: false,
  removeUndefined: isProdFlavor,
  replace: isProdFlavor,
   simplify: isProdFlavor,
  simplifyComparisons: isProdFlavor,
   typeConstructors: isProdFlavor,
  undefinedToVoid: isProdFlavor
 })

@MDendura
Copy link

@INRIX-Xiaodi-Huang I've had the same error when updating babili-webpack-plugin from 0.0.11 to 0.1.1. Are you using that too?

@arthurmchr
Copy link

arthurmchr commented Jun 14, 2017

Using babili version 0.1.3 I got the error

@boopathi
Copy link
Member

Can you share the stack trace ?

@arthurmchr
Copy link

Error: /Users/arthur/Documents/jean/gabrielle.js: Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`
    at NodePath.replaceWith (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/path/replacement.js:139:11)
    at swap (/Users/arthur/Documents/jean/node_modules/babel-plugin-minify-constant-folding/lib/index.js:42:10)
    at PluginPass.CallExpression (/Users/arthur/Documents/jean/node_modules/babel-plugin-minify-constant-folding/lib/index.js:171:16)
    at newFn (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/arthur/Documents/jean/node_modules/babel-traverse/lib/index.js:114:17)

@damianobarbati
Copy link

same here! +1

@boopathi
Copy link
Member

@j-f1
Copy link
Contributor

j-f1 commented Jun 14, 2017

@boopathi I have no idea. It appears that all of the methods used return nodes. Can anyone provide an example snippet that fails?

@boopathi boopathi changed the title New error in latest version... Don't use path.replaceWith() with a source string, use path.replaceWithSourceString() Jun 14, 2017
@michaeltrim
Copy link

+1

@j-f1
Copy link
Contributor

j-f1 commented Jun 15, 2017

@michaeltrim Can you provide an example code snippet that fails?

@johnryan
Copy link

@j-f1 Any suggestions for how to figure out what line of code is failing? There's not much in the stack trace so finding the failing chunk of code seems pretty impossible in a large project.

@damianobarbati
Copy link

guys I have no way to provide snippets for the fail :(

@michaeltrim
Copy link

michaeltrim commented Jun 16, 2017

Not sure how to provide a code snippet that fails.

I get the Error:

ERROR in unknown: Don't use path.replaceWith() with a source string, use path.replaceWithSourceString()

when I run yarn run build-main and do a stack trace before the error is thrown I get the following, not sure if that helps:

at NodePath.replaceWith (/myapp/node_modules/babel-traverse/lib/path/replacement.js:140:13)
at swap (/myapp/node_modules/babel-plugin-minify-constant-folding/lib/index.js:42:10)
at PluginPass.CallExpression (/myapp/node_modules/babel-plugin-minify-constant-folding/lib/index.js:171:16)
at newFn (/myapp/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (/myapp/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/myapp/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/myapp/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/myapp/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/myapp/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/myapp/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/myapp/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/myapp/node_modules/babel-traverse/lib/path/context.js:115:19)
at TraversalContext.visitQueue (/myapp/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/myapp/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/myapp/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/myapp/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/myapp/node_modules/babel-traverse/lib/path/context.js:115:19)
at TraversalContext.visitQueue (/myapp/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitMultiple (/myapp/node_modules/babel-traverse/lib/context.js:103:17)
at TraversalContext.visit (/myapp/node_modules/babel-traverse/lib/context.js:190:19)
at Function.traverse.node (/myapp/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/myapp/node_modules/babel-traverse/lib/path/context.js:115:19)
at TraversalContext.visitQueue (/myapp/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/myapp/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/myapp/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/myapp/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/myapp/node_modules/babel-traverse/lib/path/context.js:115:19)
at TraversalContext.visitQueue (/myapp/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitMultiple (/myapp/node_modules/babel-traverse/lib/context.js:103:17)
at TraversalContext.visit (/myapp/node_modules/babel-traverse/lib/context.js:190:19)
at Function.traverse.node (/myapp/node_modules/babel-traverse/lib/index.js:114:17)

@michaeltrim
Copy link

I can see that the method path.replaceWith() is getting passed a string of "[object Object]"

j-f1 added a commit to j-f1/forked-babili that referenced this issue Jun 16, 2017
People were calling `"foo".toString() or ["foo", "bar"].toString()`, which returned the real JS string `"[object Object]"`, the stringified version of the replacements object.
@j-f1
Copy link
Contributor

j-f1 commented Jun 16, 2017

@michaeltrim Can you try replacing node_modules/babel-plugin-minify-constant-folding/lib/index.js with this patched version to see if that fixes it?

@michaeltrim
Copy link

@j-f1 That has fixed the error when running yarn run build-main, thank you.

yarn run package still doesn't complete but this may be unrelated just doing some investigation and will let you know.

@michaeltrim
Copy link

@j-f1 So the build does eventually work but I'm getting an out of memory error in the source map generator, not sure if this is connected but it didn't occur before

]
[1] <--- Last few GCs --->
[1]
[1] [1887:0x102801600] 428064 ms: Mark-sweep 1398.8 (1570.2) -> 1398.8 (1570.2) MB, 2901.9 / 0.0 ms allocation failure GC in old space requested
[1] [1887:0x102801600] 431103 ms: Mark-sweep 1398.8 (1570.2) -> 1398.6 (1539.2) MB, 3038.7 / 0.0 ms last resort
[1] [1887:0x102801600] 434050 ms: Mark-sweep 1398.6 (1539.2) -> 1398.6 (1539.2) MB, 2946.1 / 0.0 ms last resort
[1]
[1]
[1] <--- JS stacktrace --->
[1]
[1] ==== JS stack trace =========================================
[1]
[1] Security context: 0x1781caa29891
[1] 2: addMapping(aka SourceMapGenerator_addMapping) [/myapp/node_modules/babel-generator/node_modules/source-map/lib/source-map-generator.js:~94] [pc=0x3c00c07f75d0](this=0x3b3ccc65e509 <a SourceMapGenerator with map 0x3e8f0d3f4da1>,aArgs=0x30deb9bd3279 <an Object with map 0x3e8f0d3fa289>)
[1] 3: arguments adaptor frame: 3->1
[1] 4: InnerArrayForEa...
[1]
[1] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
[1] 1:
[1] node::Abort() [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 4: v8::internal::Factory::NewUninitializedFixedArray(int) [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 5:
[1] v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacity(v8::internal::Handlev8::internal::JSObject, unsigned int) [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 6:
[1] v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/michaeltrim/.nvm/versions/node/v8.1.2/bin/node]
[1] 7: 0x3c00bf40437d
[1] npm run build-rendere

@michaeltrim
Copy link

Believe memory issue related to #332

@frzi
Copy link

frzi commented Jun 16, 2017

@j-f1 This patch fixed the issue for me as well. Thanks!

@damianobarbati
Copy link

@j-f1 is a patch about to be release soon?

@j-f1 j-f1 mentioned this issue Jun 16, 2017
@j-f1
Copy link
Contributor

j-f1 commented Jun 16, 2017

I was just checking to see if that fixed the problem. The PR above includes that fix.

vigneshshanmugam pushed a commit that referenced this issue Jun 19, 2017
* Should fix #576

People were calling `"foo".toString() or ["foo", "bar"].toString()`, which returned the real JS string `"[object Object]"`, the stringified version of the replacements object.

* Prettier code means prettier green checkmarks

* Testing testing 123

* Forgot the parens around the object literal

* Semicolons!

* npm run format
@Xazzzi-CT
Copy link

Is this on npm yet? Asking because i still get this error message.

@MikeLP
Copy link

MikeLP commented Jun 19, 2017

It's really urgent.

@ahumphreys87
Copy link

ahumphreys87 commented Jun 19, 2017 via email

@damianobarbati
Copy link

Just tried the 0.1.1 and it's broken as well 😱

@ahumphreys87
Copy link

ahumphreys87 commented Jun 20, 2017 via email

@damianobarbati
Copy link

@ahumphreys87 yep, using that for now thanks!

@ahumphreys87
Copy link

ahumphreys87 commented Jun 20, 2017 via email

@vigneshshanmugam
Copy link
Member

New version is released now with this fix https://github.com/babel/babili/releases/tag/babili%400.1.4

@LeeeeeeM
Copy link

LeeeeeeM commented Nov 2, 2018

problems with babel-traverse...em...

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

No branches or pull requests