Maybe I deleted something on package.json
but I wrote again (I not uninstalled)
I get this bug:
Error: Cannot find module 'debug'
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:UsersLeofase2node_modulesnodemonlibnodemon.js:1:75)
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)
error Command failed with exit code 1.
I am lost!! what is causing the problem?
asked May 2, 2019 at 8:55
You seem to have debug
module missing in your node_modules.
npm install debug --save
will solve the issue,also it will create an entry in package.json for the package.
For further info have a look at official docs
answered May 2, 2019 at 8:58
Shubham DixitShubham Dixit
9,0244 gold badges23 silver badges45 bronze badges
It could be an issue with your local node_modules directory. I would recommend deleting and re-installing it fresh. Then check your local dependencies to see if debug is included again.
Before you attempt the below, make sure you are in your project folder!
To do so, delete the folder node_modules
and use npm install debug
to re-install. If this fails you can check the created log for any specific errors that occurred during installation.
answered May 2, 2019 at 9:04
RobStewardRobSteward
1751 silver badge10 bronze badges
FYI, I got this error because I moved my start.js outside of the folder that had node_modules
(was separating code into two different projects).
I thought I could start the sever all the same using node ../start.js
and maybe I could have with a little more debugging, but I moved all my code back into the folder tree that had my package.json and node_modules
and that fixed it.
answered Jun 14, 2021 at 17:14
efreedefreed
96111 silver badges17 bronze badges
BEFORE YOU SUBMIT please read the following:
Delete what isn’t applicable below
I’m submitting a bug report
Webpack Version:
4.1.0
Babel Core Version:
6.0.0
Babel Loader Version:
7.1.4
Please tell us about your environment:
Ubuntu 16.04
Current behavior:
When running the webpack command, it throws an exception for every file it’s meant to handle regardless of what it looks like. Without the babel-loader, webpack builds fine.
Unfortunately, it seems to be complaining about some missing module called ‘debug’ (?) which I don’t reference or use anywhere.
Expected/desired behavior:
Hoping babel-loader will fix my issue with webpack bundles not working in IE10. I use ‘const’ and IE 10 and lower is a peach.
- If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.
My config file:
module.exports = {
entry: {
wideLayout: [
vendor + 'jquery/dist/jquery.min.js',
vendor + 'jquery-ui-dist/jquery-ui.min.js',
vendor + 'bootstrap/dist/js/bootstrap.min.js',
vendor + 'blueimp-file-upload/js/jquery.iframe-transport.js',
vendor + 'loggly-jslogger/dist/loggly.tracker-2.2.2.min.js',
sharedScripts + 'utils/common-utils.js',
sharedScripts + 'utils/common-popup-utils.js',
sharedScripts + 'utils/dialog.js',
modules + 'layout.js'
]
},
output: {
path: destinationDirectory,
filename: '[name].bundle.[chunkhash].js',
libraryTarget: 'var',
library: 'Layout'
},
module: {
rules: ([
{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: vendor + "babel-loader",
options: {
presets: ['@babel/presets-env'],
plugins: ['@babel/plugin-transform-runtime'],
babelrc: false
}
}
},
{
test: /.scss$/,
use: ExtractTextPlugin.extract({
use: [{
loader: vendor + "css-loader",
options: {
alias: {
"../fonts/bootstrap": vendor + "/bootstrap-sass/assets/fonts/bootstrap",
"../images/": vendor + "bootstrap-sass/assets/images/"
}
}
}, {
loader: vendor + "sass-loader",
options: {
includePaths: [
path.resolve(vendor)
]
}
}]
})
}
]).concat(defaultRulesConfig)
},
resolve: {
alias: {
$: path.resolve(__dirname, vendor + 'jquery/dist/jquery.min.js'),
_LTracker: path.resolve(__dirname, vendor + 'loggly-jslogger/dist/loggly.tracker-2.2.2.min.js')
},
modules: [sourceDirectory, vendor, sharedScripts, sharedAssets]
},
plugins: defaultPluginConfig.concat([
new FileChangerPlugin({
change: [
createReplacementConfig(layoutsDirectory + '/Default.html', ['defaultLayout'])
]
})
])
};
The resulting trace looks like this, and is the same for every non-vendor file in that entry:
ERROR in ../shared-scripts/utils/dialog.js
Module build failed: Error: Cannot find module 'debug'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/path/to/node_modules/babel-traverse/lib/path/index.js:17:15)
at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/path/to/node_modules/babel-traverse/lib/index.js:10:13)
at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/path/to/node_modules/babel-template/lib/index.js:69:22)
at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/path/to/node_modules/babel-helpers/lib/helpers.js:5:22)
at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
@ multi ./../node_modules/jquery/dist/jquery.min.js ./../node_modules/jquery-ui-dist/jquery-ui.min.js ./../node_modules/bootstrap/dist/js/bootstrap.min.js ./../node_modules/blueimp-file-upload/js/jquery.iframe-transport.js ./../node_modules/loggly-jslogger/dist/loggly.tracker-2.2.2.min.js ./../shared-scripts/utils/common-utils.js ./../shared-scripts/utils/common-popup-utils.js ./../shared-scripts/utils/dialog.js ./modules/layout.js
I haven’t been able to locate an issue like this through google, so here I am.
EDIT: OOOk…. so… npm i -g debug
has changed my build error to
ERROR in ./path/to/shared-scripts/utils/dialog.js
Module build failed: Error: Cannot find module './src/node'
That’s… something.
When you are working in Node, you will sometimes encounter the error Cannot find module 'module-name'
with the error code MODULE_NOT_FOUND
.
The error looks like this:
internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module 'module'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
In this post, we’ll learn how to resolve this error.
What is the problem?
The issue is that Node is unable to find the module that you are trying to import into your Node application.
The most common reason for this is that you simply haven’t installed the project’s dependencies yet.
The project’s dependencies are listed in the package.json
file at the root of the project.
The Solution
To fix the Cannot find module
error, simply install the missing modules using npm
.
To so, you can use the following command:
npm install
If you are using the yarn
package manager, you can use the following command:
yarn install
This will install the project’s dependencies into your project so that you can use them.
Sometimes, this might still not resolve it for you. In this case, you’ll want to just delete your node_modules
folder and lock file (package-lock.json
or yarn.lock
) and try again.
This is how you can delete the node_modules
folder and lock files:
rm -rf node_modules
rm package-lock.json
rm yarn.lock
Local files
If your module is not coming from a remote source, you are seeing the error because the path to the local file is not correct.
Try to confirm that the path pointing to the local module is correct and your error should be resolved.
Conclusion
The Cannot find module
error is a common error that usually happens when dependencies are not installed. Once you install your dependencies and ensure that the paths are correct, you can resolve the error and run your application successfully.
Hopefully, this resolved the issue for you.
Thanks for reading!
If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!
-
Support Us
-
Join
-
Share
-
Tweet
-
Share
Give feedback on this page!
If you’re a developer that works with Node JS and JavaScript libraries and frameworks like React, Vue, and Angular, then you might have encountered the «Error: cannot find module» error.
In this article, I’m going to show you how to fix the error.
Why the «Error: cannot find module» Occurs
This error occurs because of the following reasons:
- you’re trying to import an item from a module you don’t have installed in your project directory
- you’re importing some things from an outdated package
- you’re pointing to a file that does not exist
In the screenshot below, you can see that I’m getting the error:
I’m getting the error because I’m trying to import the freeCodeCamp icon from the react-icons package, which I don’t have installed.
import { FaFreeCodeCamp } from "react-icons/fa";
How to Fix the «cannot find module» Error
If you get this error, the solution is always in the error. The module (package) not found is always specified in the format «Module not found: Error: Can’t resolve ‘package name’ in ‘project directory».
In my case, I got it like this «Module not found: Error: Can’t resolve ‘react-icons/fa’ in ‘C:UsersuserDesktopProjectsAddress Locatoraddress-locatorsrc'».
To fix the error, you need to install the package that is absent in your project directory – npm install package-name
or yarn add package-name
.
In my case, I need to install the react-icons
package so the freeCodeCamp icon can be resolved. I’ll do that by running yarn add react-icons
.
Once I install the package and run the app, everything should successfully compile:
If you install the package but you still get the error, then follow the steps below:
- delete the node modules folder by running
rm -rf node_modules
- delete package.lock.json file by running
rm -f package-lock.json
- clean up the NPM cache by running
npm cache clean --force
- install all packages again by running
npm install
That should fix the error for you.
Conclusion
When you get the “cannot find module” error, or “module not found”, it means you’ve not installed the package you’re trying to use.
If the error occurs even if you have the package installed, then the fixes suggested in this article can help you out.
Thank you for reading.
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
I made a nodeJS app using puppeteer-extra
and some puppeteer-extra-plugins
, debugging the source code works just fine. It also runs OK when I pack it into an .exe
file using https://www.npmjs.com/package/pkg.
However, when the .exe is moved to a different directory than the ‘output’ directory, I’m getting the error
Cannot find module 'debug'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings
and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable
and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call
using process.cwd() or process.execPath.
I never use the debug
module, it must be required internally by some of my dependencies… but how can I handle this error?
I’ve got these requires
const puppeteer = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra'));
const StealthPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-stealth'));
const RecaptchaPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-recaptcha'));
const UserPrefsPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-user-preferences'));
and my package.json (config for pkg)
"pkg": {
"scripts": [
"node_modules/puppeteer/lib/*.js"
],
"assets": [
"./node_modules/@types",
"./node_modules/typescript/lib/*.d.ts",
"src/**/*.ts",
"./tsconfig.json"
],
"targets": [
"node8-win32"
]
}
Introduction
If you are trying to run your Node.js application and you get something
like this:
Error: Cannot find module 'C:UsersMemy_app.js'
then you are most likely trying to run the wrong file. It is possible
you are missing a dependency that is needed from npm install
,
but if it says it cannot
find the main file you are trying to run, then you are
trying to run a file that does not exist. It is a common mistake.
How to fix «Error: Cannot find module»
You need to double check you are running the correct file from the
correct directory. Here are some steps to diagnose.
General tips
Here are some general things to keep in mind when diagnosing the issue:
- Make sure you are in the correct directory.
- Make sure you are trying to run the correct file name.
- File and directory names are case sensitive.
How to change directories
To change directories, use the cd
command in your terminal.
For example, if your username was Me
on the computer:
# In Windows
cd C:UsersMemy_project_directory
# In Mac OS
cd /Users/Me/my_project_directory/
# In Linux
cd /home/Me/my_project_directory/
How to see what directory you are in
To check what directory you are currently in, use the folowing in your terminal.
# In Linux/Mac
pwd
# In Windows
echo %cd%
How to print the contents of current directory
To see what files and directories exist in your current directory
use the following in your terminal:
# In Windows
dir
# In Linux/Mac
ls
Conclusion
After reading this you should have some idea why you get
the error Error: Cannot find module
and how to diagnose and
fix the problem.
So i’m testing a plugin and i want to create a docker instance of wordpress in the root directory of the plugin with
wp-env start
I’m on ubuntu 20.04 LTS, i’ve installed npm and nodejs.
dara@hp-laptop-ubuntu-20-04-lts:~$ npm -v
6.14.4
dara@hp-laptop-ubuntu-20-04-lts:~$ nodejs -v
v10.19.0
however when i try to start the instance I get
dara@hp-laptop-ubuntu-20-04-lts:~$ wp-env start
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '../build/Debug/nodegit.node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@wordpress/env/node_modules/nodegit/dist/nodegit.js:19:12)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
There’s a nodegit.node in Build/Release but not in Debug folder with nodegit in it …