簡體   English   中英

node.js:錯誤:找不到模塊

[英]node.js: Error: Cannot find module

為什么會出現此錯誤?

Node v8.9.1

var childProcess = require('child_process'),
    phantomjs = require('/var/bin/node_modules/phantomjs-prebuilt');

console.error = function(){
    require('system').stderr.write(Array.prototype.join.call(arguments, ' ')+'\n');
    phantomjs.exit(1);
};

console.log('hey', phantomjs.path)
console.error('error')

childProcess.execFile(phantomjs.path, require('system').args, function(err, stdout, stderr){
    if(err){
        console.error(err);
    }

    if(stderr){
        console.error(stderr);
    }

    console.log(stdout);
});

錯誤

# /var/bin/node_modules/phantomjs-prebuilt/bin/phantomjs phantom.js
Error: Cannot find module 'path'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require
  phantomjs://platform/phantomjs.js:10
hey undefined
TypeError: undefined is not a function (evaluating 'phantomjs.exit(1)')

  phantomjs://code/phantom.js:6 in error
error

system不是Node內置模塊, 而是PhantomJS的一部分 如果僅使用標准的node命令運行腳本,則它將不可用。 如文檔所示 ,您需要使用phantomjs命令,如下所示:

phantomjs phantom.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM