fix: when a package is installed using CNPM 'TypeError require(...……) is not a function' occurs
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
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.
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
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
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
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 I'll try adding tests