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

Created on 13 Jun 2017  Â·  31Comments  Â·  Source: babel/minify

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

bug

Most helpful comment

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

All 31 comments

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

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
 })

@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?

Using babili version 0.1.3 I got the error

Can you share the stack trace ?

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)

same here! +1

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

+1

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

@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.

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

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)

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

@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?

@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.

@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 ,aArgs=0x30deb9bd3279 )
[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::Local, v8::Local) [/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 >::GrowCapacity(v8::internal::Handle, 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

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

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

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

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

It's really urgent.

I've downgraded to 0.0.11 while waiting. If it's breaking production builds
then you could do the same.

I think they said it would be released this afternoon. If downgrading is
too much trouble

On Mon, 19 Jun 2017 at 17:53 Yan Zhabin notifications@github.com wrote:

It's really urgent.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/babel/babili/issues/576#issuecomment-309500685, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACZOuC1MLhDyJN2KYoUMjrl_CWsA_3eZks5sFqeigaJpZM4N43b0
.

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

0.0.11
On Tue, 20 Jun 2017 at 08:47 damiano.barbati notifications@github.com
wrote:

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

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/babel/babili/issues/576#issuecomment-309672665, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACZOuCoAIe9kCjYj5pI7dMfi3ArDA63bks5sF3ksgaJpZM4N43b0
.

@ahumphreys87 yep, using that for now thanks!

Awesome, fingers crossed the fix version won't be long
On Tue, 20 Jun 2017 at 08:56 damiano.barbati notifications@github.com
wrote:

@ahumphreys87 https://github.com/ahumphreys87 yep, using that for now
thanks!

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/babel/babili/issues/576#issuecomment-309674539, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACZOuHzVhlXtNe8VBbMX3-0JgZNhO0xiks5sF3sXgaJpZM4N43b0
.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

babel-bot picture babel-bot  Â·  3Comments

Reinmar picture Reinmar  Â·  4Comments

kangax picture kangax  Â·  4Comments

GabbeV picture GabbeV  Â·  3Comments

zamb3zi picture zamb3zi  Â·  3Comments