question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack build error `Uncaught SyntaxError: Unexpected token /`

See original GitHub issue

Hello, just tried to integrate extract-css-chunks-webpack-plugin to my project after successfully integrated react-universal-component and redux-first-router which are amazing 😃

I encounter a problem by simply transforming my ExtractTextPlugin to ExtractCssChunks. Here is my config:

module: {
    rules: {
        test: /\.s?css$/,
        exclude: /node_modules\/^(?!prismjs)/,
        use: ExtractCssChunks.extract({
                fallback: 'style-loader',
                use: [
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                            modules: true,
                            localIdentName: '[name]__[local]',
                        },
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                    {
                        loader: 'sass-loader',
                        options: {
                            sourceMap: true,
                            sourceComments: true,
                        },
                    },
                ],
            }),
    }),
},
new ExtractCssChunks({
                filename: '[name].css',
                allChunks: false,
            },
        ),

The webpack compilation is OK and I have no warning, but when I try to load my website, I get an error: Uncaught SyntaxError: Unexpected token / which refer to this piece of built code:

if (true) {
	module.hot.accept();
	if (module.hot.data) {
		var neverUsed = 1501864374091
		__webpack_require__("./node_modules/extract-css-chunks-webpack-plugin/hotModuleReplacement.js")("/", "index.css");
	}
}
require("__webpack_require__."./node_modules/extract-css-chunks-webpack-plugin/hotModuleReplacement.js"

Problem is at

//                             👇
require("__webpack_require__."./node_modules/extract-css-chunks-webpack-plugin/hotModuleReplacement.js"

I absolutely don’t know why this problem occurs, and if I replace all my occurrences of ExtractCssChunks by ExtractTextPlugin, it works well, but I get the warning:

[UNIVERSAL-IMPORT] no css chunks hash found at "window.__CSS_CHUNKS__". Make sure you are using: https://www.npmjs.com/package/extract-css-chunks-webpack-plugin . If you are not serving CSS, disregard this message.

Sorry if this is not a bug, I’ll put this question/issue on stackoverflow.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
GuillaumeCiscocommented, Aug 18, 2017

Just discovered that removing fallback: 'style-loader', make it works. Maybe it will help.

2reactions
faceyspaceycommented, Aug 4, 2017

You actually dont need it for SPAs. You’re right. So disregard that warning–it’s just a warning. In the future, i’ll find a way to hide it for people with your use case.

Both packages dont need to be used together. You dont need webpack-flush-chunks. And definitely not in your case.

Here’s what I would do: either make the demo look like the unique parts of your setup:

https://github.com/faceyspacey/universal-demo

or make your setup look like the demo.

Do as much as you can to combine the 2 in order to find what’s causing the breakage, starting with the webpack config. Maybe try with less loaders. You know, just setup some simple files and try to find what could be breaking it. Plenty of people every day are getting it to work in Reactlandia chat. If you have any problems we can meet there this weekend 😃

Dont forget to read today’s article and spread the news!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack error bundle.js:1 Uncaught SyntaxError: Unexpected ...
I running server localhost and get error bundle.js:1 Uncaught SyntaxError: Unexpected token < In output bundle.js is html code of index.html ...
Read more >
Uncaught SyntaxError: Unexpected token < #205 - GitHub
I just get the error: "bundle.js:1 Uncaught SyntaxError: Unexpected token <" located on line 1 of my JS file titled "bundle.js".
Read more >
Webpack lesson - Uncaught SyntaxError: Unexpected token ...
Why do I get "Uncaught SyntaxError: Unexpected token import"? Compiling works ok. I am doing this lessons https://laracasts.com/series/webpack-for-everyone/ ...
Read more >
Syntax Error: Unexpected token while bundling with webpack
Greetings, My question is related to configuration of babel/webpack to be able to use nodeJS modules - and unrelated to K6 as such....
Read more >
webpack/webpack - Gitter
I am getting an error saying "Uncaught SyntaxError: Unexpected token <" while trying to run app using webpack-hot-middleware. And it is not building...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found