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.

Missing assets from loadable-stats.json

See original GitHub issue

šŸ› Bug Report

We are receiving the following error when generating HTML via our server-side-rendering process.

  const nodeStats = path.join(process.cwd(), 'build/node/loadable-stats.json')
  const webStats = path.join(process.cwd(), 'build/loadable-stats.json')

  const nodeExtractor = new ChunkExtractor({
    statsFile: nodeStats, outputPath: path.resolve(process.cwd(), 'build/node')
  })
  const { default: App, React, renderToString } = nodeExtractor.requireEntrypoint()
  const webExtractor = new ChunkExtractor({
    statsFile: webStats, outputPath: path.resolve(process.cwd(), 'build/web')
  })

Hereā€™s the error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:112:11)
    at Object.extname (path.js:1231:5)
    at getFileScriptType (/Users/noah/work/lib/node_modules/@loadable/server/lib/ChunkExtractor.js:49:60)
    at isScriptFile (/Users/noah/work/lib/node_modules/@loadable/server/lib/ChunkExtractor.js:53:10)
    at /Users/noah/work/lib/node_modules/@loadable/server/lib/ChunkExtractor.js:366:11

It appears that the cause is related to the way the assets within the loadable-stats.json block is generated.

Hereā€™s the loadable-stats.json using 5.15

{
  "hash": "aeebda487075c80e6709",
  "publicPath": "/",
  "outputPath": "/Users/nmarkon/work/content-site-connect2local/build/node",
  "assetsByChunkName": {
   ...snip..
  },
  "assets": [
    {
      "type": "assets by status",
      "cached": true,
      "filteredChildren": 70,
      "size": 281927
    }
  ],

In 5.14.2 the assets block in contained information regarding each chunk such as:

{
  "hash": "4ee6a975c8dd4cdbc020",
  "version": "5.37.0",
  "time": null,
  "publicPath": "/",
  "outputPath": "/Users/noah/work/lib/build/node",
  "assetsByChunkName": {
   .... snip....
  },
  "assets": [
    {
      "type": "asset",
      "name": "static/js/name-goes-here.d2b992cb.chunk.js",
      "size": 3518,
      "emitted": false,
      "comparedForEmit": false,
      "cached": true,
      "info": {
        "immutable": true,
        "contenthash": "d2b992cb",
        "javascriptModule": false,
        "minimized": true
      },
      "chunkNames": [
        "name-goes-here"
      ],
      "chunkIdHints": [],
      "auxiliaryChunkNames": [],
      "auxiliaryChunkIdHints": [],
      "related": {},
      "chunks": [
        4677
      ],
      "auxiliaryChunks": [],
      "isOverSizeLimit": false
    },
...snip... 

It looks like this change is the root cause: https://github.com/gregberge/loadable-components/commit/9ad6bf569a28ff553a5adf5104b55c6dcba47016

It appears that the all: false is preventing the cached assets from being added. If cachedAssets: true is added to the JSON then the cached assets are added as expected.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
depoulocommented, May 25, 2021

Iā€™m having the same issue. However, removing all: false grows the stats file a lot when using Webpack 5 (from 180 kB to 108 MB in my case), so I can understand why it was added. Could we maybe expose all options to the user facing API?

My use case, for example, works just fine with the currently set options when I replace all: false with

moduleAssets: false,
dependentModules: false,
children: false,
chunkModules: false,
entrypoints: false,
orphanModules: false,
modules: false,
providedExports: false,
relatedAssets: false,

I could also provide a pull request if I get a ā€œgoā€ from a maintainer.

0reactions
depoulocommented, Aug 3, 2021

Update to my above suggestion

I misunderstood @Noah-Vivial: he does not want to remove all: false, but merely add cachedAssets: true, which:

  • is perfectly reasonable in terms of output file size, and
  • fixes my issue as well.

So #778 is probably overkill, feel free to close it might still serve other use cases. Iā€™ve created #779 instead, and also published an according git tag to be used with npm / yarn: depoulo/loadable-components#@loadable/webpack-plugin/cached-assets-770/5.15.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering - Loadable Components
When running your build, notice @loadable/webpack-plugin generates a file called loadable-stats.json , which contains information about all your entries andĀ ...
Read more >
CSS modules not working in loadable-components in server ...
I have checked the stats.json file and it is missing the CSS files. webpack.config.js: 'use strict'; const fs = require('fs'); const pathĀ ...
Read more >
Stats Data - webpack
Stats Data. When compiling source code with webpack, users can generate a JSON file containing statistics about modules. These statistics can be used...
Read more >
@react-loadable/revised - npm package | Snyk
Looks like @react-loadable/revised is missing a security policy. ... Based on project statistics from the GitHub repository for the npm packageĀ ...
Read more >
Webpack-imported NPM | npm.io
SSR API Ā· importedAssets(stats, chunks, [tracker]) - return all assets associated with provided chunks. Could be provided a tracker to prevent duplicationsĀ ...
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