0
此代碼在Windows上正常工作,沒有任何錯誤。節點Linux/Windows兼容性問題
var express = require('express')
, app = express()
, async = require('async')
, bodyParser = require('body-parser')
, cookies = require('cookies')
, cors = require('cors')
, fileUpload = require('multer')
, fs = require('fs')
, moment = require('moment')
, morgan = require('morgan')
, path = require('path')
, session = require('express-session')
, upload = fileUpload({ dest: './uploads' })
, uuid = require('uuid')
;
var connLaw = require('./nodeHelperFunctions/datasources').service
, connPG = require('./nodeHelperFunctions/datasources').postgis
, headers = require('./helperHtml/headers')
, footers = require('./helperHtml/footers')
, passCheck = require('./nodeHelperFunctions/hashsalt')
;
但是,當在Amazon Linux AMI盒上運行相同的代碼時,出現以下錯誤。
module.js:471
throw err;
^
Error: Cannot find module './nodeHelperFunctions/datasources'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/ec2-user/testbed/js/app.js:17:59)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
試圖改變我的代碼
var connLaw = require(path.join(__dirname, 'nodeHelperFunctions/datasources')).service
, connPG = require(path.join(__dirname, 'nodeHelperFunctions/datasources')).postgis
, headers = require(path.join(__dirname, 'helperHtml/headers'))
, footers = require(path.join(__dirname, 'helperHtml/footers'))
, passCheck = require(path.join(__dirname, 'nodeHelperFunctions/hashsalt'))
;
再次完美地工作在Windows,但有在Linux上類似的錯誤:
module.js:471
throw err;
^
Error: Cannot find module '/home/ec2-user/testbed/js/nodeHelperFunctions/datasources'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/ec2-user/testbed/js/app.js:17:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
?我怎樣才能的人劇本我寫了自己當他們在Windows上完美工作時在Linux上工作?
'/ home/ec2-user/testbed/js/nodeHelperFunctions/datasources'這是正確的路徑嗎? 「nodeHelperFunctions」目錄在哪裏? – Joe
@akaphenom這可能是正確的答案,請嘗試將路徑名從cammelCase更改爲破折號,或者甚至是下劃線格式 –
@saul是對的,如果使用破折號,則需要區分大小寫。我(現在)使用所有文件和目錄名稱的破折號,以及腳本中的變量的camelCase。我很多年前就已經被燒掉了(確定2014),並在當時切換到Ubuntu開發環境, – akaphenom