出现如下错误:
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'MyPromise.js'
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> (G:\web\es6\test\dist\/TestMyPromise.js:5:41)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module._compile (G:\web\es6\test\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.newLoader [as .js] (G:\web\es6\test\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:599:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 running: `babel-node ./dist/TestMyPromise.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 running script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\34973\AppData\Roaming\npm-cache\_logs\2020-04-25T13_50_55_382Z-debug.log
Process finished with exit code 1
可能的解决方案
同一目录下的文件,比如:
可能你的引入方式错了,如下:
import Promise from "MyPromise";
正确的方式应该是这样的:
import Promise from "./MyPromise";