nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.54k stars 492 forks source link

Webpack cannot resolve flexsearch #422

Closed fourdim closed 10 months ago

fourdim commented 10 months ago

Module not found: Can't resolve 'flexsearch' Webpack says: Field 'browser' doesn't contain a valid alias configuration

❯ pnpm build

> getting-started-using-a-configuration@1.0.0 build /home/projects/webpack-webpack-js-org-mxjueg
> webpack

assets by status 69.7 KiB [cached] 1 asset
runtime modules 1010 bytes 5 modules
cacheable modules 532 KiB
  ./src/index.js 361 bytes [built] [code generated]
  ./node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js 531 KiB [built] [code generated]

ERROR in ./src/index.js 2:0-36
Module not found: Error: Can't resolve 'flexsearch' in '/home/projects/webpack-webpack-js-org-mxjueg/src'
resolve 'flexsearch' in '/home/projects/webpack-webpack-js-org-mxjueg/src'
  Parsed request is a module
  using description file: /home/projects/webpack-webpack-js-org-mxjueg/package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/projects/webpack-webpack-js-org-mxjueg/src/node_modules doesn't exist or is not a directory
      looking for modules in /home/projects/webpack-webpack-js-org-mxjueg/node_modules
        single file module
          using description file: /home/projects/webpack-webpack-js-org-mxjueg/package.json (relative path: ./node_modules/flexsearch)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch is not a file
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.json doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.wasm doesn't exist
        existing directory /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch
          using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: .)
            using description file: /home/projects/webpack-webpack-js-org-mxjueg/package.json (relative path: ./node_modules/flexsearch)
              no extension
                Field 'browser' doesn't contain a valid alias configuration
                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch is not a file
              .js
                Field 'browser' doesn't contain a valid alias configuration
                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.js doesn't exist
              .json
                Field 'browser' doesn't contain a valid alias configuration
                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.json doesn't exist
              .wasm
                Field 'browser' doesn't contain a valid alias configuration
                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch.wasm doesn't exist
              as directory
                existing directory /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch
                  using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: .)
                    use ./dist/flexsearch.bundle.module.min.js from module in package.json
                      using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: ./dist/flexsearch.bundle.module.min.js)
                        no extension
                          aliased from description file /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json with mapping './dist/flexsearch.bundle.module.min.js' to 'dist/flexsearch.bundle.module.min.js'
                            Parsed request is a module
                            using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: .)
                              resolve as module
                                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/node_modules doesn't exist or is not a directory
                                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/node_modules doesn't exist or is not a directory
                                looking for modules in /home/projects/webpack-webpack-js-org-mxjueg/node_modules
                                  /home/projects/webpack-webpack-js-org-mxjueg/node_modules/dist doesn't exist
                                /home/projects/node_modules doesn't exist or is not a directory
                                /home/node_modules doesn't exist or is not a directory
                                /node_modules doesn't exist or is not a directory
                        .js
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.module.min.js.js doesn't exist
                        .json
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.module.min.js.json doesn't exist
                        .wasm
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.module.min.js.wasm doesn't exist
                        as directory
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.module.min.js is not a directory
                    use ./dist/flexsearch.bundle.min.js from main in package.json
                      using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: ./dist/flexsearch.bundle.min.js)
                        no extension
                          aliased from description file /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json with mapping './dist/flexsearch.bundle.min.js' to 'dist/flexsearch.bundle.min.js'
                            Parsed request is a module
                            using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: .)
                              resolve as module
                                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/node_modules doesn't exist or is not a directory
                                /home/projects/webpack-webpack-js-org-mxjueg/node_modules/node_modules doesn't exist or is not a directory
                                looking for modules in /home/projects/webpack-webpack-js-org-mxjueg/node_modules
                                  /home/projects/webpack-webpack-js-org-mxjueg/node_modules/dist doesn't exist
                                /home/projects/node_modules doesn't exist or is not a directory
                                /home/node_modules doesn't exist or is not a directory
                                /node_modules doesn't exist or is not a directory
                        .js
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.min.js.js doesn't exist
                        .json
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.min.js.json doesn't exist
                        .wasm
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.min.js.wasm doesn't exist
                        as directory
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/dist/flexsearch.bundle.min.js is not a directory
                    using path: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/index
                      using description file: /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/package.json (relative path: ./index)
                        no extension
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/index doesn't exist
                        .js
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/index.js doesn't exist
                        .json
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/index.json doesn't exist
                        .wasm
                          /home/projects/webpack-webpack-js-org-mxjueg/node_modules/flexsearch/index.wasm doesn't exist
      /home/projects/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

webpack 5.89.0 compiled with 1 error in 1085 ms
 ELIFECYCLE  Command failed with exit code 1.

Reproduction: https://stackblitz.com/edit/webpack-webpack-js-org-mxjueg?file=package.json

After removing browser field, everything works fine.

ts-thomas commented 10 months ago

Thanks for the report. It is solved

> getting-started-using-a-configuration@1.0.0 build
> webpack

asset main.js 84.8 KiB [emitted] [minimized] (name: main) 1 related asset
runtime modules 1010 bytes 5 modules
orphan modules 15.9 KiB [orphan] 1 module
cacheable modules 548 KiB
  ./src/index.js + 1 modules 16.3 KiB [built] [code generated]
  ./node_modules/lodash/lodash.js 531 KiB [built] [code generated]
  worker_threads (ignored) 15 bytes [optional] [built] [code generated]
webpack 5.89.0 compiled successfully in 799 ms