fusionjs / fusion-cli

Migrated to https://github.com/fusionjs/fusionjs
MIT License
140 stars 37 forks source link

ansi-color fails to bundle with 'Octal literal in strict mode' possibly due to fusion-cli's default babelification of node_modules #622

Closed lxe closed 5 years ago

lxe commented 5 years ago

Type of issue

Bug

Description

If you import ansi-color package and attempt to fusion {dev/build} to bundle the project, the build fails with this error:

SyntaxError: /Users/aleksey/ansi-colors-app-test/node_modules/ansi-color/lib/ansi-color.js: Octal literal in strict mode (35:18)

  33 |   var ansi_str = "";
  34 |   for(var i=0, attr; attr = color_attrs[i]; i++) {
> 35 |     ansi_str += "\033[" + ANSI_CODES[attr] + "m";
     |                   ^
  36 |   }
  37 |   ansi_str += str + "\033[" + ANSI_CODES["off"] + "m";
  38 |   return ansi_str;

Steps to reproduce

$ yarn create fusion-app ansi-colors-app-test
$ cd ansi-colors-app-test
$ yarn add ansi-color@0.2.1

$ patch -p1 <<EOF
diff --git a/src/main.js b/src/main.js
index b7729d6..d89fddb 100644
--- a/src/main.js
+++ b/src/main.js
@@ -5,0 +6 @@ import Styletron from 'fusion-plugin-styletron-react';
+import 'ansi-color'
EOF

$ yarn build

Your environment

KevinGrandon commented 5 years ago

So we can reproduce your build environment, do you have a .fusionrc.js file? If so, can you share the contents of that file here?

lxe commented 5 years ago

@KevinGrandon it's empty. See repro steps. This happens in vanilla scaffold.

lhorie commented 5 years ago

Yep, easily reproducible. Maybe a misconfiguration? https://github.com/babel/babel/issues/5240

vicapow commented 5 years ago

curious if there was any update on this? for now we have to patch fusion using the following mechanism so it doesn't add the use_strict directive. This is an issue impacting more than just this module. Any module published to npm that relies on non-use_strict behavior is impacted.

vicapow commented 5 years ago
    {
      name: `Fix D3, protobuf and other modules that should not be prefixed with 'use strict;'`,
      details: '',
      file: './node_modules/fusion-cli/build/compiler.js',
      original: `
            /node_modules\\/react-dom\\//,
            /node_modules\\/react\\//,
            /node_modules\\/core-js\\//,`,
      patch: `
            /node_modules\\/react-dom\\//,
            /node_modules\\/react\\//,
            // -- START PATCH FIX -- //
            // see: web-monorepo:/common/server/scripts/patches/index.js
            /node_modules\\/d3\\//,
            /node_modules\\/@uber\\/react-auto\\//,
            /node_modules\\/keymaster\\//,
            /node_modules\\/ansi-color\\//,
            /node_modules\\/webgl-debug\\//,
            // -- END PATCH FIX -- //
            /node_modules\\/core-js\\//,`,
    },