ng serve : Cannot find module './templates.js' - node.js

I just transfered my Angular 6 project from one computer to another and in the new device I get the following error when trying to ng serve
I have also tried with npm install templates.js , the dependency is installed but this error pops again
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)
This could be similar to ng serve: Cannot find module 'tapable'
Thanks in Advance :)

Removing the node_modules folder and again using npm install solves the problem , and the ng serve working good

It can occur for two reasons:
1. templates.js is not present.
2. templates.js is present but you provided the wrong relative path.
Kindly check once. And you don't need to install "templates.js" if it's not an external package. Npm install is used for installing the external packages.

Related

Internal/modules/cjs/loader.js: 584 error

I am facing an error when I am running npm commands for running a umi app project. This is the error I see when I run the code.
I have tried checking the node module for the loader.js file but I have not been able to find it.
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module '#nodelib/fs.stat'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (C:\Users\cyhc9\umiapp\node_modules\fast-glob\out\adapters\fs-stream.js:17:14)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
The code should run when I run npm commands or the project commands.
Possible solutions:
Try not to have space in your directory name, i.e.: fun project/nestjs/..., try this: fun-project/nestjs/....
Remove node_modules and package-lock.json then do npm install again to see if that solve the problem.
Clear node cache by npm cache clean --force then repeat step number 2.
Keep trying npm i again.
Buy a new computer.
Good luck.

cannot find module './framer' after deleting node modules

I was cleaning up the angular code and, deleted some unused custom modules. After which, It was throwing an error about a deleted imported component in app.module.ts even though it was already removed from import.
Then, I manually deleted the node modules, ran npm install and tried to run npm start which gives me the following error:
Cannot find module './framer'
Error: Cannot find module './framer'
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> (C:\Users\NBS627\eclipse-workspace\ccmobile-
UI\node_modules\spdy-transport\lib\spdy-transport\protocol\base\index.js:7:18)
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)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (C:\Users\NBS627\eclipse-workspace\ccmobile-
UI\node_modules\spdy-transport\lib\spdy-transport.js:10:27)
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)
I have no idea about this error. Please help.
Your error says that you have a problem with your spdy-transport module.
To solve this you must update your spdy-transport module:
npm un spdy-transport
Then:
npm i spdy-transport
One of the packages which you deleted might have a dependency on an existing module
for example, when we do npm install package-name, often more than one folder are created in the node_modules folder, we may think that it is not required but it is in fact needed

Node : Cannot find module common

I was running a node server w/o any issue and for some purpose had to remove the node_modules dir and re-install the dependencies. Upon doing so and running the server again I get this error :
Error: Cannot find module './common'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Work\Cinde-Node\node_modules\debug\src\node.js:236:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
I installed common separately using npm install common but that didnt solve the problem.
How do I fix this ?
It looks like you have a line like
require('./common');
it should be
require('common')
I was getting the same error when I tried running my express project. The following command helped me to fix the issue.
rm package-lock.json && rm -r node_modules && npm i --save --legacy-peer-deps

Error: Cannot find module './grunt/config' when building on TravisCI

TravisCI is throwing an error when trying to run tests for my application. However, it works fine on my local. Until recently the node_modules folder was in the .gitignore so wasn't in the repository. Therefore TravisCI ran npm install to install all the modules. But since I've committed node_modules this is the error that is appearing:
Error: Cannot find module './grunt/config'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at gRequire (/home/travis/build/fender/dmeapp/node_modules/grunt/lib/grunt.js:23:24)
at Object.<anonymous> (/home/travis/build/fender/dmeapp/node_modules/grunt/lib/grunt.js:39:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
You can see the full travis build here:
https://travis-ci.org/fender/dmeapp/builds/29427422
And this is the code repository if you need to see the Gruntfile etc:
https://github.com/fender/dmeapp
Any insight into what's happening here would be greatly appreciated!
It seems you excluded or accidentially deleted the config.js file at node_modules/grunt/lib/grunt/. Compare your folder with the Grunt source repo.

npm doesn't work on an ARM embedded device

I installed Node.js on an embedded device running with a core Linux 3.0.
When I try to execute npm to install some modules, I get the follow issue :
DM-37x# npm
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /usr/local/bin/npm:18:11
at Object.<anonymous> (/usr/local/bin/npm:86:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I already tried to reinstall node.js but the bug is still here.
How can I do to fix this problem?
Try installing (or reinstalling) npmlog.
See https://www.npmjs.org/package/npmlog
Make sure you have a package.json file in the top level of your project directory (each project).
Use npm ls
and
npm update
to make sure the npmlog package is included.

Resources