stevenvachon / universal-url-lite

A smaller Universal WHATWG URL, for Browserify/etc.
MIT License
7 stars 0 forks source link

TypeError: _universalUrl.URL is not a constructor #26

Closed xmaysonnave closed 4 years ago

xmaysonnave commented 4 years ago

@stevenvachon

I was using previously whatwg-url and I try to reduce the overall size of my dapp.

1 - No issue to switch from whatwg-url to universal-url. My DApp is running correctly and the tests are running.

2 - I added the recommended snippet:

  "browser": {
    "universal-url": "universal-url-lite/native"
  },

in my package.json and tried to build. It's crashing with the following output :

Error executing boot module $:/plugins/ipfs/ipfs-uri.js: {}

$:/plugins/ipfs/ipfs-uri.js:881
  var defaultApiUrl = new _universalUrl.URL("https://ipfs.infura.io:5001");
                      ^

TypeError: _universalUrl.URL is not a constructor
    at $:/plugins/ipfs/ipfs-uri.js:881:23
    at Object.<anonymous> ($:/plugins/ipfs/ipfs-uri.js:1032:3)
    at Object.7.@babel/runtime/helpers/asyncToGenerator ($:/plugins/ipfs/ipfs-uri.js:1034:4)
    at o ($:/plugins/ipfs/ipfs-uri.js:1:632)
    at r ($:/plugins/ipfs/ipfs-uri.js:1:798)
    at $:/plugins/ipfs/ipfs-uri.js:1:827
    at $:/plugins/ipfs/ipfs-uri.js:1:88
    at $:/plugins/ipfs/ipfs-uri.js:1:323
    at Script.runInContext (vm.js:133:20)
    at Script.runInNewContext (vm.js:139:17)

Not sure where this error is coming. Any help will be greatly appreciated.

3 -Do you have any plan to upgrade the whatwg-url version you are using ?

4 - Here is the project I try to migrate.

https://github.com/xmaysonnave/tiddlywiki-ipfs

Thanks

stevenvachon commented 4 years ago

3 -Do you have any plan to upgrade the whatwg-url version you are using ?

Yes. Hopefully before summer.

Did you exclude the lib from parsing, per the readme?

xmaysonnave commented 4 years ago

Thanks for your fast reply.

As a rule never do a technical report at the end of the day... :-) Yes you're right I've forgotten to exclude the lib yesterday while I did it a few weeks ago when I evaluated the lib however I made a step forward.

1 - I successfully build my app with universal-url-lite and a got it up and running. I'm quite happy with the reduced size. However, here is the problem I faced a few weeks ago. The following is running without issue.

npx browserify \
  src/ipfs-uri.js \
  -s IpfsUri \
  -o build/plugins/ipfs/ipfs-uri.js \
  --noparse="/work/tiddly/tiddlywiki-ipfs/node_modules/universal-url-lite/lite.js" \
|| exit 1

but relative url do not seems to work and this is an issue as my github travis will have some issues with that. When I do the following :

npx browserify \
  src/ipfs-uri.js \
  -s IpfsUri \
  -o build/plugins/ipfs/ipfs-uri.js \
  --noparse="node_modules/universal-url-lite/lite.js" \
|| exit 1

The build is crashing and I got that :

Error: Cannot find module './url-state-machine' from '/work/tiddly/tiddlywiki-ipfs/node_modules/universal-url-lite'

2 - Unable to build with native :

npx browserify \
  src/ipfs-uri.js \
  -s IpfsUri \
  -o build/plugins/ipfs/ipfs-uri.js \
  --noparse="/work/tiddly/tiddlywiki-ipfs/node_modules/universal-url-lite/lite.js" \
  --noparse="/work/tiddly/tiddlywiki-ipfs/node_modules/universal-url-lite/native.js" \
|| exit 1

I tried with or without lite.js and native.js each time I got the same result :

TypeError: _universalUrl.URL is not a constructor

3 - I'm glad to know that you plan to upgrade the lib.

To summarize if I can solve the relative url issue it will be good for me. Would love to evaluate the native shim though.

Warmly

xmaysonnave commented 4 years ago

I made a step forward.

According to the following report the noparse option should have an absolute URL: https://github.com/browserify/browserify/issues/1308#issuecomment-114948552 With the $PWD my build is up and running. I need to qualify this solution on Travis though. Let's say that this problem is solved. Only the native issue remains.

Thanks

xmaysonnave commented 4 years ago

I finally found out why I got this exception. I successfully build and run the native implementation. The issue came from my build chain and the way TiddlyWiki loads its modules. Thanks for your support.