3

Tried to use npm start with Create React App to launch my react application, but got this error:

node:internal/modules/cjs/loader:943
  throw err;
  ^

Error: Cannot find module './keywords'
Require stack:
- D:\social-ribbon\node_modules\ajv-keywords\index.js
- D:\social-ribbon\node_modules\webpack\node_modules\schema-utils\src\validateOptions.js
- D:\social-ribbon\node_modules\webpack\node_modules\schema-utils\src\index.js
- D:\social-ribbon\node_modules\webpack\lib\SourceMapDevToolPlugin.js
- D:\social-ribbon\node_modules\webpack\lib\WebpackOptionsApply.js
- D:\social-ribbon\node_modules\webpack\lib\webpack.js
- D:\social-ribbon\node_modules\react-scripts\scripts\start.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Function.Module._load (node:internal/modules/cjs/loader:773:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (D:\social-ribbon\node_modules\ajv-keywords\index.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19) {
  requireStack: [
    'D:\\social-ribbon\\node_modules\\ajv-keywords\\index.js',
    'D:\\social-ribbon\\node_modules\\webpack\\node_modules\\schema-utils\\src\\validateOptions.js',
    'D:\\social-ribbon\\node_modules\\webpack\\node_modules\\schema-utils\\src\\index.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\SourceMapDevToolPlugin.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\WebpackOptionsApply.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\webpack.js',
    'D:\\social-ribbon\\node_modules\\react-scripts\\scripts\\start.js'
  ]
}

Someone suggested searching for a file called "keywords", but that word only appears in files as part of ajv-keywords or css-color-keywords. Someone else advised reinstalling the entire node-modules folder, but that sounds a bit drastic. I'm now asking you for help. Thanks for any help.

mikwee
  • 133
  • 2
  • 14
  • Is there a file called `keywords.js`? If there is, can you share how your folder structure looks like? – Rukshan Jayasekara Jun 20 '21 at 16:21
  • 1
    As I said, no file name contains `keywords`, it only appears *in* files as part of these two packages/modules. – mikwee Jun 20 '21 at 16:45
  • Can you add the code, where you use the import from the `keywords` module? Then it'll be easier to identify the issue. – Rukshan Jayasekara Jun 20 '21 at 16:49
  • 1
    Noticed I didn't have the `keywords` package, so I installed it, but it still showed the same error. I searched `keywords` again, and it obviously appeared, but only in `package-lock.json`, `package.json` & `yarn.lock` (Tried to move to Yarn, and tbh, everything went downhill from there). – mikwee Jun 20 '21 at 19:14

2 Answers2

4

I also faced the same problem. What I did was removed the node modules folder and reinstalled it. I will also share the commands

 rm -R node_modules
 npm cache --force clean
 npm cache --force clear
 npm install
 npm start

Hope this works. It worked form me, but in my case, there was a folder of avj-keywords.

Sibtain Wani
  • 89
  • 1
  • 9
0

Assuming you import it as "Keywords",

Change import Keywords from './keywords' to import Keywords from 'keywords'

You don't need to use relative paths when importing packages from node_modules.

Rukshan Jayasekara
  • 1,945
  • 1
  • 6
  • 26