Module not found: Error: Can't resolve 'xlsx' in 'd:\crx\crx-bus\src'

There are a compile-time error ts project:

Module not found: Error: Can't resolve 'xlsx' in 'd:\crx\crx-bus\src'

Project environment:

- webpack v4.x

- ts-loader v5.x

- xlsx v0.15.4

analysis

Literally from error, xlsx like this when looking for a third-party package, can not find the src directory. This package should be looking for my son from node_modules years.

debugging

In scripts npm's added after webpack command parameters:

webpack  --display-error-details

Observe more detailed error display.

Find clues:

We can see from the richer error message, look for the modules they traverse the various extensions in node_modules / xlsx years, in an attempt to find xlsx, but they were not found.

poor:

So I open node_modules / xlsx, found its main properties in package.json value ./xlsx, not with the extension, and directory provided xlsx.js, extension js.

Antidote:

I checked webpack.conf.js configuration, added the extension .js

  resolve: {
    extensions: ['.ts', '.js', '.d.ts'],
  },
 
So far, the problem is solved.

Guess you like

Origin www.cnblogs.com/duxing/p/12116427.html