Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Issue building a simple example with Parcel #1509

Closed
acailly opened this issue Aug 15, 2018 · 8 comments
Closed

Issue building a simple example with Parcel #1509

acailly opened this issue Aug 15, 2018 · 8 comments
Labels
example exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue kind/support A question or request for support

Comments

@acailly
Copy link

acailly commented Aug 15, 2018

I tried to build the following example: https://gist.github.com/acailly/648d1a6e28c8939bbdf84499851c626d
(on Windows 10 64bits)

I have the following error:

×  C:\_Projets\temp\test-parcel-browser\node_modules\fs-ext\fs-ext.js:22:22: Cannot resolve dependency './build/Release/fs-ext' at 'C:\_Projets\temp\test-parcel-browser\node_modules\fs-ext\build\Release\fs-ext'
  20 | "use strict";
  21 |
> 22 | var binding = require('./build/Release/fs-ext');
     |                       ^
  23 | var fs = require('fs');
  24 | var constants = require('constants');
  25 |

It seems that browser field is not correctly handled by parcel (it tries to create a repo with node config instead of browser config).
I asked the question in parcel-bundler/parcel#1883 but the stange thing is that the same example works very well if we replace ipfs with another dependency that uses the browser field (like on-load, see https://gist.github.com/acailly/986047b786bf2dc247ea47bd2b0a1115)

I failed to identify the root cause and have no clue.

I'm posting this here hopping that my simple reproducible use case will help in completing #1436

@alanshaw alanshaw added kind/support A question or request for support exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue example status/ready Ready to be worked labels Aug 16, 2018
@mkg20001
Copy link
Contributor

Just guessing: This might be an issue because of wrong handling of paths/path-matching on windows as they usually get added unix-style to the browser field. ?

@raoulmillais
Copy link
Contributor

raoulmillais commented Nov 22, 2018

I narrowed this down to dignifiedquire/lock-me. This gist is a minimal test case that demonstrates the above error.

Adding "fs-events": false to the browser field in js-ipfss' package.json or (better IMO) dignifiedquire/lock-me resolves the build failure and running parcel build index.html works. Unfortunately running the parcel dev server using parcel index.html results in a runtime parcel build error in the browser console and the stack trace isn't terribly illuminating. At this point I'm not convinced this isn't a problem with parcel on windows and this comment suggests the maintainers aren't supporting windows officially.

@raoulmillais
Copy link
Contributor

The runtime parcel build error was a related issue with lock-me being required in the browser. lock-me is pulled in by js-ipfs-repo but it has been replaced with proper-lockfile in 0.25.1. In the latest version ipfs-repo specifies an in memory lock shim for the browser in the browser field of its package.json. So even though parcel build and parcel run no longer error when building the bundle and shimming the fs, it's just pushed the problem to runtime instead of build time.

I thought this corroborated @mkg20001's hypothesis so I went on to create an even more minimal test case to prove/disprove parcel's browser shimming behaviour on windows:

  1. Create 2 packages
    • package A has an index.js file that requires a local sibling package, package B and
    • package B requires a file dep.js and has a browser field with "./dep.js" : "./shim.js".
    • shim.js console.logs 'i am the shim'
    • dep.js console.logs 'I am the default'
  2. parcel build .\index.js inside package A
  3. node .\dist\index.js

This outputs 'i am the shim' and looking at the .\dist\index.js bundle it appears that parcel did the right thing.

For completeness, I tried again with the browser shim specified in a package one level deeper I.E. A -> B -> C where package C specified the shim and ran parcel build again in package A. Parcel.js again did the right thing and included only the shim file.

I'm confused, the browser shim behaviour should work as expected

@raoulmillais
Copy link
Contributor

raoulmillais commented Nov 22, 2018

The bug in parcel on windows only show itself when the browser field is a relative path with more than one component. I.E.

  1. Create 2 packages
    • package A has an index.js file that requires a local sibling package, package B
    • package B requires a file ./src/dep.js and has a browser field with "./src/dep.js": "./src/shim.js"
    • shim.js console.logs 'i am the shim'
    • dep.js console.logs 'I am the default'
  2. parcel build .\index.js inside package A
  3. node .\dist\index.js

I'll move this conversation to the parcel issue.

@alanshaw
Copy link
Member

@raoulmillais could you link us to the issue on the parcel repo?

@raoulmillais
Copy link
Contributor

Sure thing @alanshaw it is the issue linked in the description

@raoulmillais
Copy link
Contributor

There is a PR with a working (on unix) parceljs example with some further notes

@alanshaw
Copy link
Member

Now that #1726 exists, lets close this :)

@ghost ghost removed the status/ready Ready to be worked label Nov 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
example exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

4 participants