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

Failed to minify code in create-react-app project #56

Closed
diminator opened this issue Jun 19, 2018 · 5 comments
Closed

Failed to minify code in create-react-app project #56

diminator opened this issue Jun 19, 2018 · 5 comments
Assignees

Comments

@diminator
Copy link
Contributor

> react-scripts build

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 

        ./node_modules/bigchaindb-orm/dist/browser/bigchaindb-orm.cjs2.min.js:24:24739 

Read more here: http://bit.ly/2tRViJ9
@kremalicious
Copy link
Contributor

kremalicious commented Jun 20, 2018

Have you tried importing the source of the driver, not the dist files? create-react-app does its own babel transpilation, but not on files imported from node_modules

@diminator
Copy link
Contributor Author

Have you tried importing the source of the driver, not the dist files? create-react-app does its own babel transpilation

I'm assuming this is the responsibility of the imported package?

Maybe we should rework the build settings?

@kremalicious
Copy link
Contributor

To answer my own suggestion: importing from source doesn't work either. When importing directly from the source folder in a create-react-app project like so:

import Orm from 'bigchaindb-orm/src'

A new warning comes up upon build, now complaining about the same thing but for js-bigchaindb-driver:

> react-scripts build

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 

 	./node_modules/bigchaindb-driver/dist/browser/bigchaindb-driver.cjs2.min.js:25:24726

@kremalicious kremalicious changed the title Failed to minify code Failed to minify code in create-react-app project Jul 25, 2018
@kremalicious kremalicious changed the title Failed to minify code in create-react-app project Failed to minify code in create-react-app project Jul 25, 2018
@kremalicious
Copy link
Contributor

For reference, we solved this temporarily by copying the respective files into the CRA src directory before build, passing them to CRA's own transpilation. That's a workaround until either:

Here's the script:

#!/usr/bin/env bash

set -e

cp -R ./node_modules/bigchaindb-driver/dist/node/ ./src/lib/bigchaindb-driver
cp -R ./node_modules/bigchaindb-orm/src/ ./src/lib/bigchaindb-orm
cp -R ./node_modules/decamelize/ ./src/lib/decamelize

replaceStrings () {
    # remove 'use strict'; from all js files
    if [[ "$OSTYPE" == "darwin"* ]]; then
        sed -i "" "s|'use strict';||g" "$1"
    else
       sed -i "s|'use strict';||g" "$1"
    fi

    # replace require/import calls with local versions
    if [[ "$OSTYPE" == "darwin"* ]]; then
        sed -i "" "s|'bigchaindb-driver'|'../bigchaindb-driver'|g" "$1"
        sed -i "" "s|'decamelize'|'../decamelize'|g" "$1"
    else
        sed -i "s|'bigchaindb-driver'|'../bigchaindb-driver'|g" "$1"
        sed -i "s|'decamelize'|'../decamelize'|g" "$1"
    fi
}

for i in ./src/lib/**/*.js; do
    replaceStrings "$i"
done

for i in ./src/lib/**/**/*.js; do
    replaceStrings "$i"
done

printf '\n👍 Successfully copied BigchainDB drivers. Hooray!\n\n   See why we are doing this:\n   https://github.com/bigchaindb/js-driver-orm/issues/56\n'

@jernejpregelj
Copy link
Contributor

Update react-scripts to at least, bug will be fixed with new react release:
"react-scripts": "2.0.0-next.3e165448"

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

No branches or pull requests

3 participants