gpt4 book ai didi

node.js - 使用 require() 并导入私有(private) npm 模块失败

转载 作者:太空宇宙 更新时间:2023-11-04 00:41:06 25 4
gpt4 key购买 nike

我正在尝试导入在 sinopia 托管的私有(private) npm 模块。我可以看到我的模块在 sinopia 文件夹结构中可用。

能够通过“npm install --save”安装模块。我可以看到它从本地注册表中选择它。

但是当我在任何地方使用它时,我收到“错误:找不到模块”

var module = require('some-module'); 
(tried both)
import module from 'some-module';

ERROR in ./app/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../node_modules/test-module in c:\yotest\app
@ ./app/index.js 39:34-77

P.S:我确实尝试将其安装为全局 Node 模块,但再次失败。

编辑:

这是我的私有(private)模块的 package.json,它是来自 github 项目的克隆。

    {
"_args": [
[
"react-worker-dom",
""
]
],
"_from": "react-worker-dom@latest",
"_id": "react-worker-dom@0.0.3",
"_inCache": true,
"_installable": true,
"_location": "/react-worker-dom",
"_nodeVersion": "5.7.1",
"_npmUser": {},
"_npmVersion": "3.6.0",
"_phantomChildren": {},
"_requested": {
"name": "react-worker-dom",
"raw": "react-worker-dom",
"rawSpec": "",
"scope": null,
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_shasum": "01b520589b7fd9d5533f911108ac6e1f774dab79",
"_shrinkwrap": null,
"_spec": "react-worker-dom",
"_where": "",
"author": {
"email": "******************",
"name": "********************"
},
"bugs": {
"url": "https://github.com/web-perf/react-worker-dom/issues"
},
"dependencies": {
"invariant": "^2.2.0",
"react": "^0.14.3"
},
"description": "ReactJS renderer using Web Workers",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"babel-preset-stage-0": "^6.1.18",
"browser-perf": "^1.4.3",
"react-dom": "^0.14.3",
"webpack": "^1.12.8",
"webpack-dev-server": "^1.14.1"
},
"directories": {
"test": "test"
},
"dist": {
"shasum": "01b520589b7fd9d5533f911108ac6e1f774dab79",
"tarball": "http://localhost:4873/react-worker-dom/-/react-worker-dom-0.0.3.tgz"
},
"gitHead": "8c8fb15e793151e0169aac82537f4efe628d9986",
"homepage": "http://web-perf.github.io/react-worker-dom",
"license": "BSD-3-Clause",
"main": "dist/worker.js",
"name": "react-worker-dom",
"optionalDependencies": {},
"publishConfig": {
"registry": "http://localhost:4873/"
},
"readme": "ERROR: No README data found!",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/web-perf/react-worker-dom.git"
},
"scripts": {
"build-demo": "webpack --config test/webpack.config.js",
"demo": "webpack-dev-server --config test/webpack.config.js",
"perf": "node test/perf.js"
},
"version": "0.0.3"
}

主项目的Webpack配置

module.exports = {
entry: './app/index.js',
output: {
filename: 'public/bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel'
}
]
}
}

主项目的Package.json文件

{
"name": "yotest",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"start": "node bin/dev-server"
},
"keywords": [
"webpack",
"redux",
"react",
"react-router",
"kyper"
],
"license": "MIT",
"dependencies": {
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^0.8.2",
"history": "^1.9.1",
"kyper-matter": "^0.1.2",
"lodash": "^3.10.1",
"proxy-middleware": "^0.13.1",
"react": "^0.14.0-rc1",
"react-dom": "^0.14.0-rc1",
"react-hot-loader": "^1.2.8",
"react-redux": "^2.1.2",
"react-router": "^1.0.0-rc1",
"react-worker-dom": "0.0.3",
"redux": "^3.0.0",
"redux-router": "^1.0.0-beta3",
"redux-thunk": "^1.0.0"
},
"devDependencies": {
"css-loader": "^0.16.0",
"eslint": "^1.4.1",
"eslint-config-airbnb": "0.0.8",
"eslint-plugin-react": "^3.2.3",
"node-sass": "^3.3.2",
"redux-devtools": "^2.1.2",
"sass-loader": "^2.0.1",
"style-loader": "^0.12.3",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
}
}

最佳答案

我已重新配置我的 NPM 专用注册表,但端口不匹配导致了该问题。

关于node.js - 使用 require() 并导入私有(private) npm 模块失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36771499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com