3

I'm getting this error on vscode:

enter image description here

This is my package.json file:

{
  "name": "font-awesome-test",
  "version": "1.0.0",
  "description": "Test font-awesome with webpack",
  "main": "index.js",
  "repository": "[email protected]:jeusdi/fontawesome-webpack.git",
  "author": "Jordi Cabré",
  "license": "MIT",
  "dependencies": {
    "font-awesome": "^4.7.0",
    "typescript": "^2.7.1"
  },
  "devDependencies": {
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.11.1"
  }
}

Any ideas?

2

3 Answers 3

5

TypeScript can understand require after adding the Node type definitions:

npm install --save-dev @types/node

Shorthand:

npm i -D @types/node

Or with yarn:

yarn add -D @types/node

Also, you'll probably want to use

"moduleResolution": "Node",

in tsconfig.json to avoid different errors like

error TS2307: Cannot find module 'abc'
Sign up to request clarification or add additional context in comments.

Comments

5

I face the same error, when checked tsconfig.app.json file, it have:

"types": []

Just changed to

"types": ["node"]

And now everything is working smooth!

Comments

1

TypeScript supports two different module resolution strategies: Classic and Node. The default is Classic.

In order to use the require('package') method, you need to change your module resolution strategy to Node in the compileOptions of your tsconfig.json:

"compilerOptions": {
  "moduleResolution": "node",
}

1 Comment

This addresses other errors like TS2307: Cannot find module 'abc' but it's not sufficient for the require error posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.