fix: when a package is installed using CNPM 'TypeError require(...……) is not a function' occurs#40
fix: when a package is installed using CNPM 'TypeError require(...……) is not a function' occurs#40jianxcao wants to merge 1 commit intopeerigon:masterfrom
Conversation
…s not a function' occurs
|
Thanks for the PR 👍 That's really odd. Do you know why cnpm doesn't stick to npm's folder structure? |
|
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 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 |
|
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 |
| // If the required file is a css-loader helper, we just require it with node's require. | ||
| // If the required file should be processed by a loader we do not touch it (even if it is a .js file). | ||
| if (/^[^!]*node_modules[/\\]css-loader[/\\].*\.js$/i.test(absPath)) { | ||
| if (/^[^!]*node_modules[/\\](_css-loader@[.\d]+@)*css-loader[/\\].*\.js$/i.test(absPath)) { |
There was a problem hiding this comment.
Shouldn 't (_css-loader@[.\d]+@)* rather be (_css-loader@[.\d]+@)? ?
There was a problem hiding this comment.
ok,(_css - loader @ [. ] d + @)? It would be better
|
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 |
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/_css-loader@0.28.11@css-loader/lib/css-base.js', so I modified the regular expression to solve this problem