node 用 require 引入 js 文件, 另一个文件可以,一个却不行,到底是什么原因,本地跑也都是没问题的,放到服务器上跑就不行了。为什么会用这么诡异的问题、、、 大家帮忙看看,3Q
引入 globalIncreId.js 不行, 引入 cnfig.js 是可以的, 文件都是有的:
$ ls -al total 124 drwxr-xr-x 4 root root 4096 Aug 16 17:33 . drwxr-xr-x 5 root root 4096 Aug 16 17:27 .. drwxr-xr-x 8 root root 4096 Aug 16 17:30 .git -rw-r--r-- 1 root root 66 Aug 16 17:27 .gitattributes -rwxr-xr-x 1 root root 31 Aug 16 17:27 .gitignore -rw-r--r-- 1 root root 10054 Aug 16 17:27 DDL.sql -rw-r--r-- 1 root root 7877 Aug 16 17:27 app.js -rw-r--r-- 1 root root 2060 Aug 16 17:27 collectConfig.js -rw-r--r-- 1 root root 2059 Aug 16 17:27 collectConfig_editing.js -rw-r--r-- 1 root root 644 Aug 16 17:28 config.js -rw-r--r-- 1 root root 129 Aug 16 17:27 db.js -rw-r--r-- 1 root root 129 Aug 16 17:27 db1.js -rw-r--r-- 1 root root 379 Aug 16 17:33 globalIncreID.js -rw-r--r-- 1 root root 545 Aug 16 17:27 globalIncreID_mysql.js -rw-r--r-- 1 root root 1236 Aug 16 17:27 myUtil.js drwxr-xr-x 20 root root 4096 Aug 16 17:27 node_modules -rw-r--r-- 1 root root 4956 Aug 16 17:27 package-lock.json -rw-r--r-- 1 root root 372 Aug 16 17:27 package.json -rw-r--r-- 1 root root 601 Aug 16 17:27 redisCli.js -rw-r--r-- 1 root root 339 Aug 16 17:27 test2.js -rw-r--r-- 1 root root 429 Aug 16 17:27 testAsync.js -rw-r--r-- 1 root root 829 Aug 16 17:27 testAsyncEach.js -rw-r--r-- 1 root root 875 Aug 16 17:27 testAsyncForever.js -rw-r--r-- 1 root root 286 Aug 16 17:27 testAsyncWhilst.js -rw-r--r-- 1 root root 219 Aug 16 17:27 testGlobalIncreID.js -rw-r--r-- 1 root root 584 Aug 16 17:27 testMysqlReturn.js -rw-r--r-- 1 root root 371 Aug 16 17:27 testSetTimeIntervalRun.js 这个不行:
const globalIncreId = require('./globalIncreId'); 报错:
$ node app.js internal/modules/cjs/loader.js:583 throw err; ^ Error: Cannot find module './globalIncreId' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15) at Function.Module._load (internal/modules/cjs/loader.js:507:25) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object.<anonymous> (/apps/unify-data/app.js:13:23) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) 这个 config 是可以的:
const cOnfig= require('./config'); 