box / box-ui-elements

React Components for Box's Design System and Pluggable Components
https://developer.box.com/docs/box-ui-elements
Other
531 stars 292 forks source link

Getting webpack error due to terser unexpected token: punc (:) #2497

Closed BustosAndrew closed 3 years ago

BustosAndrew commented 3 years ago

Environment:

Desktop (please complete the following information):

Steps to reproduce the problem:

  1. Have axios installed as an npm package
  2. Attempt to install box-ui-elements using npm

What is the expected behavior? (Screenshots can be helpful here) To be able to install the npm package without dependency issues. What went wrong? (Screenshots, console logs, or HAR files can be helpful here) Npm can't resolve dependency with axios versions. Log:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: integration@0.0.1
npm ERR! Found: axios@0.21.1
npm ERR! node_modules/axios
npm ERR!   axios@"^0.21.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer axios@"^0.18.1" from box-ui-elements@12.0.0
npm ERR! node_modules/box-ui-elements
npm ERR!   box-ui-elements@"^12.0.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/bustosman/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bustosman/.npm/_logs/2021-03-23T23_36_28_407Z-debug.log

Link to application or sample code: N/A

Expected behavior To be able to install the package without dependency conflicts.

Additional context If I force the install of the package, and then run gulp build, this is the webpack error log I get:

[00:13:30] [Webpack errors]:
[00:13:30] activity-sidebar.js from Terser
Unexpected token: punc (:) [webpack://./node_modules/box-ui-elements/node_modules/setimmediate/setImmediate.js:80,12][activity-sidebar.js:30380,18]
    at js_error (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:550:11)
    at croak (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1274:9)
    at token_error (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1282:9)
    at unexpected (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1288:9)
    at semicolon (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1326:56)
    at simple_statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1583:73)
    at statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1369:47)
    at _embed_tokens_wrapper (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1339:26)
    at block_ (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:2172:20)
    at statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1403:29)[00:13:30]

Please update the package with the newest version of axios. (.21.1) I need to continue with integrating the content explorer into a Microsoft Teams tab. I'm aware box already has an app for this in MS Teams, but it's still limited in search features from what it seems.

alexkrolick commented 3 years ago

We are indeed strictly locked onto that version of Axios at the moment. Can you try package aliasing if you need a different version in your app?

https://stackoverflow.com/questions/26414587/how-to-install-multiple-versions-of-package-using-npm#56495651

BustosAndrew commented 3 years ago

After downgrading axios, and then installing all the peer dependencies manually, running gulp build still produces the webpack error. Any idea on how to fix that? I can't find the file activity-sidebar.js.

BustosAndrew commented 3 years ago

After adding content-preview and content-sidebar to webpack for code splitting this is my new error log:

[21:37:53] [Webpack errors]:
[21:37:53] 67.js from Terser
Unexpected token: punc (:) [webpack://./node_modules/setimmediate/setImmediate.js:80,12][67.js:30817,18]
    at js_error (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:550:11)
    at croak (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1274:9)
    at token_error (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1282:9)
    at unexpected (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1288:9)
    at semicolon (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1326:56)
    at simple_statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1583:73)
    at statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1369:47)
    at _embed_tokens_wrapper (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1339:26)
    at block_ (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:2172:20)
    at statement (/Users/bustosman/Documents/GitHub/Box/Integration/node_modules/terser/dist/bundle.min.js:1403:29)

As you can see 67.js is not a file.

Here is my current webpack config:

const webpack = require("webpack");
const Dotenv = require("dotenv-webpack");
const nodeExternals = require("webpack-node-externals");
const ESLintPlugin = require("eslint-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { IgnorePlugin } = require("webpack");
// const TerserPlugin = require("terser-webpack-plugin");

const path = require("path");
const fs = require("fs");
const argv = require("yargs").argv;
const { json } = require("express");

const debug = argv.debug !== undefined;
const lint = !(argv["no-linting"] || argv.l === true);

const config = [
    {
        entry: {
            server: [path.join(__dirname, "/src/server/server.ts")]
        },
        mode: debug ? "development" : "production",
        output: {
            path: path.join(__dirname, "/dist"),
            filename: "[name].js",
            devtoolModuleFilenameTemplate: debug
                ? "[absolute-resource-path]"
                : "[]"
        },
        externals: [nodeExternals()],
        devtool: debug ? "source-map" : "source-map",
        resolve: {
            extensions: [".ts", ".tsx", ".js"],
            alias: {}
        },
        target: "node",
        node: {
            __dirname: false,
            __filename: false
        },
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    exclude: /node_modules/,
                    use: ["ts-loader"]
                }
            ]
        },
        plugins: []
    },
    {
        entry: {
            client: [path.join(__dirname, "/src/client/client.ts")],
            sidebar:
                "./node_modules/box-ui-elements/es/elements/content-sidebar/Sidebar",
            preview:
                "./node_modules/box-ui-elements/es/elements/content-preview/ContentPreview"
        },
        mode: debug ? "development" : "production",
        output: {
            path: path.join(__dirname, "/dist/web/scripts"),
            filename: "[name].js",
            libraryTarget: "umd",
            library: "integration",
            publicPath: "/scripts/"
        },
        externals: {},
        devtool: debug ? "source-map" : "source-map",
        resolve: {
            extensions: [".ts", ".tsx", ".js"],
            alias: {}
        },
        target: "web",
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    exclude: /node_modules/,
                    use: ["ts-loader"]
                },
                {
                    test: /\.css$/i,
                    use: ["style-loader", "css-loader"]
                },
                {
                    test: /\.s[ac]ss$/i,
                    use: [
                        // Creates `style` nodes from JS strings
                        "style-loader",
                        // Translates CSS into CommonJS
                        "css-loader",
                        // Compiles Sass to CSS
                        "sass-loader"
                    ]
                },
                {
                    test: /\.js$/,
                    loader: "babel-loader",
                    exclude: /(node_modules)/
                }
            ]
        },
        plugins: [
            new Dotenv({
                systemvars: true
            })
        ]
    }
];

if (lint !== false) {
    config[0].plugins.push(
        new ESLintPlugin({ extensions: ["ts", "tsx"], failOnError: false })
    );
    config[1].plugins.push(
        new ESLintPlugin({ extensions: ["ts", "tsx"], failOnError: false })
    );
}

module.exports = config;
alexkrolick commented 3 years ago

Looks like you are bundling UI Elements stand-alone from source. Can you try using the UMD builds from the dist folder that ship with the package instead?

BustosAndrew commented 3 years ago

How would I modify my current webpack config for the UMD builds?

alexkrolick commented 3 years ago

You don't need to webpack the dist/ files, they are prebuilt and ready for use in a <script> tag. You can also use the CDN approach described here: https://developer.box.com/guides/embed/ui-elements/installation/