How to resolve: Cannot find module 'xlsx'

Viewed 24

I'm trying to use the xlsx package in my UI5 project ( using typescript), but it doesn't find the module. Anyone please know how to resolve this?

This is how I import in my main.controller.ts file:

import { XLSX } from "xlsx";

This is the error:

Cannot find module 'xlsx'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?ts(2792)

This is the package.json

  "devDependencies": {
    "@babel/cli": "^7.16.0",
    "@babel/core": "^7.16.0",
    "@babel/preset-env": "^7.16.4",
    "@babel/preset-typescript": "^7.16.0",
    "@sap/ui5-builder-webide-extension": "^1.1.7",
    "@sap/ux-ui5-tooling": "1",
    "@sapui5/ts-types-esm": "1.99.2",
    "@types/jquery": "3.5.1",
    "@types/xlsx": "^0.0.36",
    "@typescript-eslint/eslint-plugin": "^5.6.0",
    "@typescript-eslint/parser": "^5.6.0",
    "@ui5/cli": "^2.14.1",
    "babel-preset-transform-ui5": "^7.0.5",
    "eslint": "^8.4.1",
    "npm-run-all": "^4.1.5",
    "typescript": "^4.5.3",
    "ui5-middleware-livereload": "^0.5.8",
    "ui5-task-zipper": "^0.4.2",
    "xlsx": "^0.18.5"
  }
1 Answers

Possibly this import is causing problems "@types/xlsx": "^0.0.36",

xlsx provides its own type definitions that possibly is in conflict with @types

Related