Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

RangeError: Maximum call stack size exceeded #49

Closed
creage opened this issue Dec 20, 2017 · 12 comments
Closed

RangeError: Maximum call stack size exceeded #49

creage opened this issue Dec 20, 2017 · 12 comments

Comments

@creage
Copy link

creage commented Dec 20, 2017

Last release causes RangeError.

NodeJS v9.2.0
NPM 5.5.1
Windows 10
preload-webpack-plugin 2.1.1
webpack 3.10.0

webpack.config is pretty simple

...
new HtmlWebpackPlugin({
	filename: 'index.html',
	template: '../index.html',
	minify: {
		collapseWhitespace: true
	},
	favicon: path.resolve(APPROOT, 'favicon.ico')
}),
new PreloadWebpackPlugin({
	rel: 'prefetch'
}),
...

Error log is

ERROR in   RangeError: Maximum call stack size exceeded
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:26 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:26:29
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
2017-12-19T07:42:13.0221845Z            
2017-12-19T07:42:13.0221845Z            - index.js:31 isChunkBelongToHtml
2017-12-19T07:42:13.0221845Z              [client]/[preload-webpack-plugin]/index.js:31:9
@jeffposnick
Copy link
Contributor

There is some recursive code in there, so I could imagine how this might happen, but at the same time, I'm not able to reproduce it.

I'm using the following, roughly based on what you provided as your config:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin')

module.exports = {
  entry: './index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index-template.html',
      minify: {
        collapseWhitespace: true
      }
    }),
    new PreloadWebpackPlugin({
      include: 'all', // Needed to get index-bundle.js prefetched.
      rel: 'prefetch'
    }),
  ]
};

Could you pass along the rest of your config? I'm assuming this has something to with with your use of a configuration that sets parent.chunks.

Also CC: @toxic-johann, as they authored #37 and might have more insight.

@creage
Copy link
Author

creage commented Dec 20, 2017

Could it be somehow connected to the use of DllPlugin? We build our main entry point as a Dll, and wire it to the initial index.html, with the additional entry point which consumes that Dll and starts the application.

new webpack.DllPlugin({
	name: 'App',
	context: APPROOT,
	path: path.resolve(DEST, 'manifest.json')
}),

@toxic-johann
Copy link
Contributor

@jeffposnick I think you guess is right. I will check this today.

@creage I'm still a little puzzled. You means you have not include chunk in htmlWebpackPlugin but through dllPlugin? If you can provide a simple full config. I may find out the bug quickly.

@creage
Copy link
Author

creage commented Dec 21, 2017

@toxic-johann well, I've tried to create a simple repo with my config, but I cannot reproduce it there either. It is rather small, having 4 modules only, but my real app has ~1300 , with complex structure of async modules. I assume some of these causes the recursion.

If you give me some hints on how could I debug this plugin, I could run it on my real app.

@toxic-johann
Copy link
Contributor

I think it may be caused by chunk ring.

Assume you have chunk, A,B,C.

A include B, B include C and then C include A..

As I backtrace the parent chunks, it bump into a dead cycle

@creage
Copy link
Author

creage commented Dec 21, 2017

OK, I've modified plugin to log chunks which cause an exception, like this:

// Only handle the chunk import by the htmlWebpackPlugin
extractedChunks = extractedChunks.filter(chunk => {
    try {
        return isChunkBelongToHtml(chunk, Object.values(htmlPluginData.assets.chunks));
    } catch (er) {

        fs.appendFileSync('preload-webpack-plugin-log.txt', (chunk.name || chunk.files) + '\n');

        return false;
    }
});

and output list of chunks actually matches the list of items, preloaded on version 2.0.0. Meaning, every item proposed for preload leads to exception. Strange...

And, trying to stringify chunk like

JSON.stringify(chunk);

leads to TypeError: Converting circular structure to JSON.

So, looks like @toxic-johann is right here. Can't we mark already visited nodes, to avoid circular recursion?

@jeffposnick
Copy link
Contributor

@toxic-johann Do you have a handle on what would need to change in order to avoid the circular references, or would you prefer some help putting together a PR?

@toxic-johann
Copy link
Contributor

Yes. I am trying to reproduce this. I think I need to do something to fix this bug.

It's good that if someone can help me.

@jeffposnick
Copy link
Contributor

I took a stab at a fix. @creage, could you switch your dependency in package.json to

"preload-webpack-plugin": "git+https://github.com/GoogleChromeLabs/preload-webpack-plugin.git#fix-circular-recursion"

and give that a try? And @toxic-johann & co., can you confirm that this still works with your setups as well?

@creage
Copy link
Author

creage commented Dec 22, 2017

@jeffposnick I confirm it compiles fine now. No exceptions, and all expected assets are added to the index.html. Thanks for the fix, and looking forward to have it released!

@toxic-johann
Copy link
Contributor

@jeffposnick Yes.It still works. That's great.

@jeffposnick
Copy link
Contributor

Great—the 2.1.2 release contains the fix. Thanks for bearing with us!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants