plotly / plotly/plotly.js

Upgrading to plotly ^3- Angular build fails with this Webpack error: java Copy Edit Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type

Open
#7,466 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

When using a recent version of plotly.js (or @plotly/mapbox), which internally depends on maplibre-gl, the build fails with this Webpack error:
./node_modules/maplibre-gl/dist/maplibre-gl.css:1:0 - Error: Module parse failed: Unexpected token (1:0)

I have a custom webpack.config.js
const webpack = require('webpack');

module.exports = (config) => {
// Add polyfills
config.resolve = config.resolve || {};
config.resolve.fallback = {
...config.resolve.fallback,
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer/')
};

config.plugins = config.plugins || [];
config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser'
})
);

// Tell webpack to ignore CSS imports from plotly.js
config.module.rules.push({
test: /.css$/,
use: 'null-loader',
include: /node_modules[/\]plotly.js/
});

return config;
};

I have it in the styles on angular.json-
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"outputPath": "dist/sizingTool-ui",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/maplibre-gl/dist/maplibre-gl.css",
"src/styles.css",
"src/theme.scss",
"node_modules/primeng/resources/themes/saga-green/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css",
"node_modules/open-iconic/font/css/open-iconic-bootstrap.min.css",
"node_modules/ngx-spinner/animations/ball-newton-cradle.css"
],
"scripts": [],

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with webpack.config.js and the Angular build configuration in angular.json, then reproduce the build using the listed maplibre-gl stylesheet and custom Webpack setup. Trace how the CSS file is processed and confirm the build completes without the reported Module parse failed error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript, webpack
Domain
build-system, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.