请用这个来拯救我的理智。
OS: Windows Server 2012 R2
Installed Nodejs via executable. This also installed npm
Tested both via cmd with npm -v and node -v. Both found.
Using cmd installed puppeteer using npm install puppeteer@9.0.0 -g
Windows 环境变量也添加了管理员的用户变量,没有空格:
Variable:NODE_PATH
Value:C:\Users\Administrator\AppData\Roaming\npm\node_modules
Variable:Path Value:C:\Users\Administrator\AppData\Roaming\npm
系统变量:
Variable: NODE_PATH
Value:C:\Users\Administrator\AppData\Roaming\npm\node_modules
Variable: Path
Value:C:\Users\Administrator\AppData\Roaming\npm;C:\Program Files (x86)\nodejs\
得到了一个我通过 cmd 运行的测试文件,如下所示:
node c:/home/pm/wwwroot/test_files/puppeteer/connect-and-check.js
文件中的第一行:
const puppeteer = require('puppeteer');
一切正常。所以CMD相关安装好
通过尝试同样的事情cfexecute
,它在第一行失败,因为找不到模块。完整错误:
错误:找不到模块 'puppeteer' 需要堆栈:-C:\home\pm\wwwroot\admin\jscripts\puppeteer\ocprocess.js
在 Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15 )
在 Function.Module._load (node:internal/modules/cjs/loader:773:27)
在 Module.require (node:internal/modules/cjs/loader:1012:19)
在 require (node:internal/modules/ cjs/helpers:93:18)
在对象。(C:\home\pm\wwwroot\admin\jscripts\puppeteer\ocprocess.js:2:19)
在 Object.Module._extensions 的 Module._compile (node:internal/modules/cjs/loader:1108:14)
。 .js (node:internal/modules/cjs/loader:1137:10) 在 Module.load (node:internal/modules/cjs/loader:988:32)
在 Function.Module._load (node:internal/modules/cjs /装载机:828:14)
在 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
{ code: 'MODULE_NOT_FOUND',
requireStack: ['C:\home\pm\wwwroot\admin\jscripts\puppeteer\ocprocess.js ' ] }
有什么想法吗?puppeteer 模块是全局安装的(也尝试过--save
,但没有区别),通过命令行工作,但通过应用程序本身失败。最糟糕的是,我们在另一个 VPS 上进行了相同的设置,实际上是相同的版本、环境变量等,并且运行良好。我错过了什么?