ng serve:找不到模块“ ./templates.js”

时间:2018-11-19 21:20:12

标签: node.js angular angular6

我刚刚将Angular 6项目从一台计算机转移到另一台计算机,并且在新设备中尝试ng serve时出现以下错误

我也尝试过使用npm install templates.js,该依赖项已安装,但此错误再次弹出

Cannot find module './templates.js'
Error: Cannot find module './templates.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\Users\Godwin\Desktop\livigro\node_modules\chalk\index.js:6:18)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\Users\Godwin\Desktop\livigro\node_modules\postcss\lib\css-syntax-error.js:9:14)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)

这可能类似于ng serve: Cannot find module 'tapable'

先谢谢了:)

2 个答案:

答案 0 :(得分:1)

它的发生可能有两个原因:

1. templates.js is not present.
2. templates.js is present but you provided the wrong relative path. 

请检查一次。而且,如果它不是外部软件包,则无需安装“ templates.js”。 Npm install用于安装外部软件包。

答案 1 :(得分:1)

删除node_modules文件夹,然后再次使用npm install解决了该问题,并且ng serve运行良好