PNPM - 启动新项目未按预期工作
PNPM - Starting new project not working as expected
我正在尝试使用集中式包管理器 (pnpm
) 而不是香草 npm
,因为我喜欢在我的硬盘上安装 space。我只是想让项目开始,运行 遇到困难,网上很少有实际指导我使用这个包管理器启动项目的方法。有没有人有过将其用于 React/React Native 的经验?
非常欢迎任何想法。
我尝试了两种不同的设置方式:
使用 pnpx create-react-app my-app
创建了一个新项目。这正是 npx create-react-app
所做的,其中包括安装超过 200MB 的模块,我已经在我的系统上安装了超过一百万次。我检查了 node_modules
文件夹和文件的 none 是硬链接,它们本身就是模块。
创建了一个没有辅助命令的新项目(即触摸 App.js、index.js、index.html 等)然后 pnpm i react...
等。这有效在某种程度上,所有节点包都链接到我的全局存储(在 ~/ 中),但是当我尝试 pnpm start
让我的服务器运行时,我收到错误:Cannot find module ... /my-project/server.js
。我没有 server.js 文件,但话又说回来,使用常规的 npm 和 npx 命令,我从来不需要一个。
我已经使用 pnpm i server
看看我是否可以让它以这种方式工作。没有什么。我是 React 的新手,所以我确定我做了一些荒谬的事情,但是无论我有多初级,我都按照官方说明 (https://pnpm.js.org/docs/en/motivation.html) 进行操作,但它们对我没有用。
pnpm 调试文件内容如下:
{
"0 debug pnpm:scope": {
"selected": 1,
"workspacePrefix": null
},
"1 error pnpm": {
"message": {
"errno": 1,
"code": "ELIFECYCLE",
"pkgid": "my-cv@1.0.0",
"stage": "start",
"script": "node server.js",
"pkgname": "my-cv"
},
"err": {
"name": "Error",
"message": "my-cv@1.0.0 start: `node server.js`\nExit status 1",
"code": "ELIFECYCLE",
"stack": "Error: my-cv@1.0.0 start: `node server.js`\nExit status 1\n at EventEmitter.<anonymous> (/usr/local/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/index.js:302:16)\n at EventEmitter.emit (events.js:200:13)\n at ChildProcess.<anonymous> (/usr/local/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/lib/spawn.js:55:14)\n at ChildProcess.emit (events.js:200:13)\n at maybeClose (internal/child_process.js:1021:16)\n at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)"
}
}
}
更新:所以我已经设法让它工作了,我想......我掌握了 npx create-react-app
中使用的所有必需的包,并将它们放在 package.json 中在执行 pnpm i
之前。但是,除了想知道这是否可能而不会遇到那么多麻烦之外,查看文件结构,除了 node_modules 文件夹中的别名外,我似乎还有一个隐藏文件夹 .registry.npmjs.org
.这与我在系统根目录中的完全相同,我认为它是中央存储。
TLDR:尽管 pnpm 似乎可以工作(别名是在 node_modules 文件夹中创建的),但我的系统上仍然有重复的包。谁能确认是不是这样?
关于磁盘 space 使用情况。 node_modules 中的包是 硬链接。 pnpm 在常见问题解答中有关于此的 a section:
pnpm creates hard links from the global store to project's node_modules folders. Hard links point to the same place on the disk where the original files are. So, for example, if you have foo in your project as a dependency and it occupies 1MB of space, then it will look like it occupies 1MB of space in the project's node_modules folder and the same amount of space in the global store. However, that 1MB is the same space on the disk addressed from two different locations. So in total foo occupies 1MB, not 2MB.
For more on this subject:
关于node_modules里面的隐藏文件夹,可以看这篇文章:Flat node_modules is not the only way.
pnpm 过去与 React Native 有问题。 pnpm 经常使用符号链接,而 React Native 不喜欢符号链接。
P.S。如果你没有得到关于 SO 的帮助,你可以随时 post 到我们的 Gitter chat
我现在意识到这是一个老问题....但它仍然没有得到充分解决(理想情况下,create-react-app 应该有一个允许它在本地使用 pnpm 的开关....但那是另一个天)。
我的解决方案有点乏味,但有效。首先,像往常一样创建你的 React 应用程序:
pnpx create-react-app my-app --template typescript
等待 npm 必要的时间下载您已经拥有的 ~350mb 的东西。接下来,运行 以下(假设 Linux):
cd my-app
rm -rf node_modules/
pnpm i
根据获得的模块数量 re-used,您将节省多达 350mb 的磁盘空间 space。
我正在尝试使用集中式包管理器 (pnpm
) 而不是香草 npm
,因为我喜欢在我的硬盘上安装 space。我只是想让项目开始,运行 遇到困难,网上很少有实际指导我使用这个包管理器启动项目的方法。有没有人有过将其用于 React/React Native 的经验?
非常欢迎任何想法。
我尝试了两种不同的设置方式:
使用
pnpx create-react-app my-app
创建了一个新项目。这正是npx create-react-app
所做的,其中包括安装超过 200MB 的模块,我已经在我的系统上安装了超过一百万次。我检查了node_modules
文件夹和文件的 none 是硬链接,它们本身就是模块。创建了一个没有辅助命令的新项目(即触摸 App.js、index.js、index.html 等)然后
pnpm i react...
等。这有效在某种程度上,所有节点包都链接到我的全局存储(在 ~/ 中),但是当我尝试pnpm start
让我的服务器运行时,我收到错误:Cannot find module ... /my-project/server.js
。我没有 server.js 文件,但话又说回来,使用常规的 npm 和 npx 命令,我从来不需要一个。
我已经使用 pnpm i server
看看我是否可以让它以这种方式工作。没有什么。我是 React 的新手,所以我确定我做了一些荒谬的事情,但是无论我有多初级,我都按照官方说明 (https://pnpm.js.org/docs/en/motivation.html) 进行操作,但它们对我没有用。
pnpm 调试文件内容如下:
{
"0 debug pnpm:scope": {
"selected": 1,
"workspacePrefix": null
},
"1 error pnpm": {
"message": {
"errno": 1,
"code": "ELIFECYCLE",
"pkgid": "my-cv@1.0.0",
"stage": "start",
"script": "node server.js",
"pkgname": "my-cv"
},
"err": {
"name": "Error",
"message": "my-cv@1.0.0 start: `node server.js`\nExit status 1",
"code": "ELIFECYCLE",
"stack": "Error: my-cv@1.0.0 start: `node server.js`\nExit status 1\n at EventEmitter.<anonymous> (/usr/local/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/index.js:302:16)\n at EventEmitter.emit (events.js:200:13)\n at ChildProcess.<anonymous> (/usr/local/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/lib/spawn.js:55:14)\n at ChildProcess.emit (events.js:200:13)\n at maybeClose (internal/child_process.js:1021:16)\n at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)"
}
}
}
更新:所以我已经设法让它工作了,我想......我掌握了 npx create-react-app
中使用的所有必需的包,并将它们放在 package.json 中在执行 pnpm i
之前。但是,除了想知道这是否可能而不会遇到那么多麻烦之外,查看文件结构,除了 node_modules 文件夹中的别名外,我似乎还有一个隐藏文件夹 .registry.npmjs.org
.这与我在系统根目录中的完全相同,我认为它是中央存储。
TLDR:尽管 pnpm 似乎可以工作(别名是在 node_modules 文件夹中创建的),但我的系统上仍然有重复的包。谁能确认是不是这样?
关于磁盘 space 使用情况。 node_modules 中的包是 硬链接。 pnpm 在常见问题解答中有关于此的 a section:
pnpm creates hard links from the global store to project's node_modules folders. Hard links point to the same place on the disk where the original files are. So, for example, if you have foo in your project as a dependency and it occupies 1MB of space, then it will look like it occupies 1MB of space in the project's node_modules folder and the same amount of space in the global store. However, that 1MB is the same space on the disk addressed from two different locations. So in total foo occupies 1MB, not 2MB.
For more on this subject:
关于node_modules里面的隐藏文件夹,可以看这篇文章:Flat node_modules is not the only way.
pnpm 过去与 React Native 有问题。 pnpm 经常使用符号链接,而 React Native 不喜欢符号链接。
P.S。如果你没有得到关于 SO 的帮助,你可以随时 post 到我们的 Gitter chat
我现在意识到这是一个老问题....但它仍然没有得到充分解决(理想情况下,create-react-app 应该有一个允许它在本地使用 pnpm 的开关....但那是另一个天)。
我的解决方案有点乏味,但有效。首先,像往常一样创建你的 React 应用程序:
pnpx create-react-app my-app --template typescript
等待 npm 必要的时间下载您已经拥有的 ~350mb 的东西。接下来,运行 以下(假设 Linux):
cd my-app
rm -rf node_modules/
pnpm i
根据获得的模块数量 re-used,您将节省多达 350mb 的磁盘空间 space。