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.

AssetGraph: assert fails .type is 'asset' instead of 'asset_group'

See original GitHub issue

🐛 bug report

When building/watching, I often get this crash

🚨 Build failed.
Error: The expression evaluated to a falsy value:

  (0, assert().default)(n.type === 'asset_group')

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  (0, _assert().default)(n.type === 'asset_group')

    at AssetGraph.removeNode (node_modules/@parcel/core/lib/AssetGraph.js:214:31)
    at AssetGraph.removeEdge (node_modules/@parcel/core/lib/Graph.js:248:12)
    at AssetGraph.removeNode (node_modules/@parcel/core/lib/Graph.js:212:14)
    at AssetGraph.removeNode (node_modules/@parcel/core/lib/AssetGraph.js:219:18)
    at AssetGraph.removeEdge (node_modules/@parcel/core/lib/Graph.js:248:12)
    at AssetGraph.removeNode (node_modules/@parcel/core/lib/Graph.js:212:14)
    at AssetGraph.removeNode (node_modules/@parcel/core/lib/AssetGraph.js:219:18)
    at AssetGraph.removeEdge (node_modules/@parcel/core/lib/Graph.js:248:12)

(when inspecting the .type, we see it’s a asset instead of asset_group).

It probably has something to do with my custom transformer: it makes 1x/2x/3x assets for require('asset:/myFile.png?size=100x100') by exposing these as extra parts in the transform step:

async transform({asset, config, options}) {
    if (!asset.query.size) {
        // probably the variant!
        asset.isIsolated = true;
        return [asset];
    }
    
    let code = 'module.exports = {\n';
    const parts = [];
    // ...
    for (variant of ["3x","2x","1x"]) {
        const result = await imagePipeline.clone().toBuffer();
        const uniqueKey = asset.id+'@'+variant;
        asset.addDependency({
            moduleSpecifier: uniqueKey,
        });
        parts.push({
             type: 'png',
             pipeline: 'asset', // ??
             uniqueKey,
             content: result,
             isIsolated: true,
         });
        code += JSON.stringify(variant) + ": require(" + JSON.stringify(uniqueKey) + "),\n";
    });
    code += '}';
    asset.type = 'js';
    asset.setCode(code);
    return [asset, ...parts];
}

Note: re-inserting the parts into the same asset: “pipeline” feels rather clunky (might be the source if the issue?), but if I don’t do it I get:

No transformers found for assets/myImage.png.

🎛 Configuration (.babelrc, package.json, cli command)

const parcel = new Parcel({
    entries: "index.html",
    distDir: 'built/',
    config: require.resolve("./.parcelrc"),
    mode: "development",
    contentHash: true,
});

await parcel.watch((e) => {
    console.log("built! ", e);
})
{
    "extends": "@parcel/config-default",
    "transformers": {
        "asset:*": ["parcel-transformer-my-asset"]
    }
}

Also, using PARCEL_WORKER_BACKEND=process env.

💻 Code Sample

I can try to extract the crash case on request, but it’s quite some work!

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.462
Node node-v14.15.1-linux-x64
npm/Yarn yarn 1.22.4
Operating System linux

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Banou26commented, Jan 19, 2021

I edited the comment last night saying that upgrading to 2.0.0-nightly.540 fixed the problem. So I think everything is all good?

0reactions
mischniccommented, Jan 19, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction | Asset Graph | 1.7.2-preview - Unity - Manual
When an error occurs in AssetGraph, a notification appears in the Asset Log. ... Split By Filter allows you to categorize assets based...
Read more >
Reg : Assertion Failed ( Assert condition was violated )
Hi genus, I try to display the ASSET ( T.Code : AS03 ) . while click display , its going to dump. i...
Read more >
assetgraph - npm
An auto discovery dependency graph based optimization framework for web pages and applications. Latest version: 7.10.0, last published: 2 ...
Read more >
Using the New Asset Bundle Browser & Graph Tool - YouTube
Enjoy a preview of new features that make working with dynamically loaded content simple and efficient, while drastically reducing ...
Read more >
Asset false statement to check if displayed - Stack Overflow
Asserting an element isn't present doesn't really work in selenium, you usually get an exception because it's trying to interact with an ...
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