[NPM] Having trouble with the phone package

Re-posting part of my comment here for @Joyce’s guidance on the NPM thread.

We’re trying to validate phone numbers, and we found the phone package.

However, when we try to use it, we get an error related to the utility_1 variable (“cannot access utility_1 before initialization”), which when looking at the code in unpkg.com looks like a module within the library.

I tried looking up a way to force this to initialize, but wasn’t able to find a solution.

Any ideas?

Yeah, this won’t work. Unpkg exposes the root file, but only really works if the package was built with UMD distribution in mind. Some are, and this is super helpful.

You can see how it was built by exploring the package in unpkg here: UNPKG - phone. Note the index file is referencing other files in the subdirectory. The script tag that weweb creates only references the index file - the others don’t come along for the ride.

A lot of node packages are not designed to be used this way - they are intended as source code help that will eventually be webpacked or what have you. So you’ll find this gives you access to some but not others.

I’m working on a bit of a package that is intended to extend the weweb functionality a bit more, and building to work properly with UMD (and so with weweb’s NPM plugin) is a specific build concern that I needed to manage as part of my process.

Hope some of the above helps for context and picking tools with this new capability!

2 Likes

Thank you, Ray. That’s very helpful.