Parcel: Issue with parcel-plugin-* and map of requires?

Created on 8 Jan 2018  路  8Comments  路  Source: parcel-bundler/parcel

Possibly a 馃悰 bug report

I'm testing my plugin to get inlined svgs instead of urls.

馃 Expected Behavior

screen shot 2018-01-07 at 23 07 10

Below a screenshot of the build file:

screen shot 2018-01-07 at 22 41 29

馃槸 Current Behavior

screen shot 2018-01-07 at 23 05 37

Below a screenshot of the build file:

screen-shot-2018-01-07-at-22 40 05

馃拋 Possible cause

I'm asking for help people!

I guess the issue is with the asset ids...

This is kinda random...
Building and building again (eg. just changing the order of the requires) sometimes will not print the duplicate 4 (expected behaviour) but most of the times the requires will have that same numeric require (100% the number 4 in my example) hence the current behaviour.
Numbers in general are sequential but often not (I don't know much about that, could you address me somewhere in the code?)
I'd like to start fixing this but I'd like to have a hint from you. Where to start? Is it my plugin? No idea yet. The plugin itself is very basic so far. Nothing fancy really.

馃捇 Code Sample

https://github.com/albinotonnina/parcel-plugin-inlinesvg/tree/master/example

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | any
| Node | > 8
| npm/Yarn | both :P
| Operating System | osx high sierra

Thanks!

Bug Help Wanted

Most helpful comment

Thanks @fathyb, it fixes for me too.

const JSAssetLib = require('parcel-bundler/lib/assets/JSAsset')
const JSAssetSrc = require('parcel-bundler/src/assets/JSAsset')

const JSAsset = parseInt(process.versions.node, 10) < 8 ? JSAssetLib : JSAssetSrc

Plugin fixed https://github.com/albinotonnina/parcel-plugin-inlinesvg

All 8 comments

Same happens with another plugin https://github.com/fansenze/parcel-plugin-url-loader by @fansenze

screen shot 2018-01-08 at 14 57 34
screen shot 2018-01-08 at 14 57 51

Does this still accure with latest master branch?

@DeMoorJasper afraid so!

I had the same on parcel-plugin-typescript (see #7). This is because two Asset.js are used, one from src and one from lib, it means that you'll get duplicated IDs. I did this as a workaround :

import JSAssetLib = require('parcel-bundler/lib/assets/JSAsset')
import JSAssetSrc = require('parcel-bundler/src/assets/JSAsset')

export const JSAsset = parseInt(process.versions.node, 10) < 8 ? JSAssetLib : JSAssetSrc

Related to #251 , the api needs some improvements to expose more internal functions in a proper way

Thanks @fathyb, it fixes for me too.

const JSAssetLib = require('parcel-bundler/lib/assets/JSAsset')
const JSAssetSrc = require('parcel-bundler/src/assets/JSAsset')

const JSAsset = parseInt(process.versions.node, 10) < 8 ? JSAssetLib : JSAssetSrc

Plugin fixed https://github.com/albinotonnina/parcel-plugin-inlinesvg

Ah, ideally plugins wouldn't extend the internal asset types at all. The API should be better about allowing composition of assets.

Closing due to inactivity and plugin api being rewritten in Parcel 2

Was this page helpful?
0 / 5 - 0 ratings