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

Unable to require @material-ui/core in ts_devserver #1116

Closed
ghost opened this issue Sep 10, 2019 · 1 comment
Closed

Unable to require @material-ui/core in ts_devserver #1116

ghost opened this issue Sep 10, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 10, 2019

🐞 bug report

Affected Rule

The issue is caused by the rule:

ts_devserver or rollup_bundle.

Possibly related to issue #1095

Is this a regression?

Did not use prior version.

Description

While attempting to include @material-ui/core in the generated bundle for devserver, I receive a 404 error attempting to fetch core.js.

Looking in the generated bazel for material-ui/core, I see:

load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle")

npm_umd_bundle(
    name = "core__umd",
    package_name = "core",
    entry_point = "//:node_modules/@material-ui/core/esm/index.js",
    package = ":core",
)

I followed the React example open in a PR. React + TS works fine, importing Material does not.

🔬 Minimal Reproduction

// app.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {Button} from '@material-ui/core';

function App() {
    return (
        <Button variant="contained" color="primary">
            Hello World
        </Button>
    );
}

ReactDOM.render(<App />, document.querySelector('#root'));
load("@build_bazel_rules_nodejs//:defs.bzl", "http_server", "rollup_bundle", "nodejs_binary")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@npm_bazel_typescript//:index.bzl", "ts_config", "ts_devserver", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
    name = "components",
    srcs = glob([
        "components/*.ts",
        "components/*.tsx",
    ]),
    deps = [
        "@npm//@types/react",
        "@npm//@types/react-dom",
    ],
)

ts_library(
    name = "app",
    srcs = glob([
            "*.ts",
            "*.tsx",
    ]),
    deps = [
        ":components",
        "@npm//@types/react",
        "@npm//@types/react-dom",
        "@npm//@material-ui/core",
    ],
)

ts_devserver(
    name = "devserver",
    index_html = "index.html",
    entry_module = "com_etsy_search/apps/tire-ui/app",
    # We'll collect all the devmode JS sources from these TypeScript libraries
    deps = [
        ":app",
        "@npm//react:react__umd",
        "@npm//react-dom:react-dom__umd",
        "@npm//@material-ui/core:core__umd",
    ],
)

rollup_bundle(
    name = "bundle",
    enable_code_splitting = False,
    entry_point = ":app.ts",
    deps = [
        ":app",
        "@npm//react",
        "@npm//react-dom",
        "@npm//@material-ui/core",
    ],
)

web_package(
    name = "package",
    assets = [
        # For differential loading, we supply both an ESModule entry point and an es5 entry point
        # The injector will put two complimentary script tags in the index.html
        ":bundle.min.js",
        ":bundle.min.es2015.js",
    ],
    index_html = "index.html",
)

🔥 Exception or Error


ts_scripts.js?v=1568084002064:169 Uncaught Error: Script error for "@material-ui/core", needed by: com_etsy_search/apps/tire-ui/app
http://requirejs.org/docs/errors.html#scripterror
    at makeError (ts_scripts.js?v=1568084002064:169)
    at HTMLScriptElement.onScriptError (ts_scripts.js?v=1568084002064:1739)
makeError @ ts_scripts.js?v=1568084002064:169
onScriptError @ ts_scripts.js?v=1568084002064:1739
error (async)
req.load @ ts_scripts.js?v=1568084002064:1944
load @ ts_scripts.js?v=1568084002064:1686
load @ ts_scripts.js?v=1568084002064:835
fetch @ ts_scripts.js?v=1568084002064:825
check @ ts_scripts.js?v=1568084002064:857
enable @ ts_scripts.js?v=1568084002064:1177
enable @ ts_scripts.js?v=1568084002064:1558
(anonymous) @ ts_scripts.js?v=1568084002064:1162
(anonymous) @ ts_scripts.js?v=1568084002064:135
each @ ts_scripts.js?v=1568084002064:60
enable @ ts_scripts.js?v=1568084002064:1114
enable @ ts_scripts.js?v=1568084002064:1558
(anonymous) @ ts_scripts.js?v=1568084002064:1162
(anonymous) @ ts_scripts.js?v=1568084002064:135
each @ ts_scripts.js?v=1568084002064:60
enable @ ts_scripts.js?v=1568084002064:1114
init @ ts_scripts.js?v=1568084002064:789
(anonymous) @ ts_scripts.js?v=1568084002064:1461
setTimeout (async)
req.nextTick @ ts_scripts.js?v=1568084002064:1816
localRequire @ ts_scripts.js?v=1568084002064:1450
requirejs @ ts_scripts.js?v=1568084002064:1798
(anonymous) @ ts_scripts.js?v=1568084002064:2163


Request URL: ...:5432/@material-ui/core.js
Request Method: GET
Status Code: 404 Not Found

🌍 Your Environment

Operating System:

  
Mac OS Mojave 10.14.5 (18F132)
  

Output of bazel version:

  
Build label: 0.28.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jul 19 15:22:50 2019 (1563549770)
Build timestamp: 1563549770
Build timestamp as int: 1563549770
  

Rules version (SHA):

  
0d9660cf0894f1fe1e9840818553e0080fbce0851169812d77a70bdb9981c946
  

Anything else relevant?

@alexeagle
Copy link
Collaborator

I agree, looks like the same issue as #1095

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

1 participant