extract-loader icon indicating copy to clipboard operation
extract-loader copied to clipboard

fix: when a package is installed using CNPM 'TypeError require(...……) is not a function' occurs

Open jianxcao opened this issue 7 years ago • 6 comments

When I used CNPM to install the package, 'TypeError require(... ...... ) is not a function error' occurred, mainly because the path of CNPM starts with _ when installing the package, such as 'node_modules/[email protected]@css-loader/lib/css-base.js', so I modified the regular expression to solve this problem

jianxcao avatar Jun 11 '18 11:06 jianxcao

Thanks for the PR 👍

That's really odd. Do you know why cnpm doesn't stick to npm's folder structure? Could you also explain why cnpm is necessary in the first place? I don't like adding these kind of changes to the code base, but if it solves a problem for a lot of users, it maybe worth it.

jhnns avatar Jun 11 '18 18:06 jhnns

Because in China, many places cannot connect to NPM, so CNPM is used instead of NPM, CNPM is the product of alibaba, I don't know why cnpm doesn't stick to npm's folder structure

jianxcao avatar Jun 12 '18 01:06 jianxcao

To simply avoid this problem, use npm (or yarn) with custom registry instead of cnpm might help:

npm config set registry https://registry.npm.taobao.org/

The underscore before the module name is generated by https://github.com/cnpm/npminstall , which works much like yarn, but builds package folders with symbolic link. For example, if you execute npminstall get-port, you will get these folders in node_modules:

get-port -> [email protected]@get-port
[email protected]@get-port

imyelo avatar Jun 12 '18 08:06 imyelo

This approach works, but it is better to be compatible with CNPM, which may be used in the server-side configuration file depending on the location of the server

jianxcao avatar Jun 12 '18 12:06 jianxcao

Ok. Although I don't really see the use-case for cnpm (since you can switch registries), I see the use-case for this fast npm install.

@jianxcao could you also add a test for this? It could be hard to test though, but please give it a try. I don't like to pull in features that are untested because they tend to break later 😁

jhnns avatar Jun 13 '18 13:06 jhnns

@jhnns I'll try adding tests

jianxcao avatar Jun 14 '18 01:06 jianxcao