facebookresearch/segment-anything

Demo error - Module not found: Error: Can't resolve 'process/browser'

Closed this issue · 4 comments

Hello, thanks for the great work. I can start the demo using the "Run the app" section of demo.README.md but I receive the following error when the page loads:

image

In App.tsx, the following files exist. I used the same model to generate the embedding.

const IMAGE_PATH = "/assets/data/dogs.jpg";
const IMAGE_EMBEDDING = "/assets/data/dogs_embedding.npy";
const MODEL_DIR = "/model/sam_onnx_quantized_example.onnx";

Node: v21.6.1
Webpack: 5.90.0

Full output:

yarn run v1.22.21
$ yarn run start-dev
$ webpack serve --config=configs/webpack/dev.js
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:8080/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.1.17:8080/
<i> [webpack-dev-server] Content not from webpack is served from '/home/bricklayer/Workspace/segment-anything/demo/public' directory
<i> [webpack-dev-middleware] wait until bundle finished: /


 ERROR  Failed to compile with 2 errors                                                                                                                                                        9:14:26 AM

 error  in ./node_modules/onnxruntime-web/dist/esm/ort.min.js

Module not found: Error: Can't resolve 'process/browser' in '/home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/esm'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

 error  in ./node_modules/onnxruntime-web/dist/esm/ort.min.js

Cannot read properties of undefined (reading 'module')

assets by path *.wasm 84.8 MiB
  asset ort-wasm-simd-threaded.jsep.wasm 18.6 MiB [emitted] [from: node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm] [copied]
  asset ort-wasm-simd.jsep.wasm 16.6 MiB [emitted] [from: node_modules/onnxruntime-web/dist/ort-wasm-simd.jsep.wasm] [copied]
  + 5 assets
assets by path assets/ 9.09 MiB
  assets by path assets/data/ 9.09 MiB 4 assets
  asset assets/index.html 532 bytes [emitted] [from: src/assets/index.html] [copied]
  asset assets/scss/App.scss 59 bytes [emitted] [from: src/assets/scss/App.scss] [copied]
assets by path model/*.onnx 55.5 MiB
  asset model/sam_onnx_example.onnx 15.7 MiB [emitted] [from: model/sam_onnx_example.onnx] [copied]
  asset model/sam_vit_h_4b8939.onnx 15.7 MiB [emitted] [from: model/sam_vit_h_4b8939.onnx] [copied]
  asset model/sam_vit_b_01ec64.onnx 15.7 MiB [emitted] [from: model/sam_vit_b_01ec64.onnx] [copied]
  asset model/sam_vit_h_4b8939_quant.onnx 8.35 MiB [emitted] [from: model/sam_vit_h_4b8939_quant.onnx] [copied]
asset main.js 2.18 MiB [emitted] (name: main) 1 related asset
asset index.html 569 bytes [emitted]
runtime modules 27.5 KiB 14 modules
modules by path ./node_modules/underscore/modules/*.js 83.1 KiB 161 modules
modules by path ./node_modules/webpack-dev-server/client/ 71.8 KiB 16 modules
modules by path ./src/ 31.4 KiB 11 modules
modules by path ./node_modules/style-loader/dist/runtime/*.js 5.84 KiB 6 modules
modules by path ./node_modules/webpack/hot/*.js 5.18 KiB 4 modules
modules by path ./node_modules/html-entities/lib/*.js 81.8 KiB 4 modules
modules by path ./node_modules/react-dom/ 1000 KiB 3 modules
modules by path ./node_modules/react/ 85.7 KiB 2 modules
modules by path ./node_modules/onnxruntime-web/dist/ 1.03 MiB 2 modules
modules by path ./node_modules/scheduler/ 17.3 KiB 2 modules
modules by path ./node_modules/css-loader/dist/runtime/*.js 2.74 KiB 2 modules
+ 5 modules

ERROR in ./node_modules/onnxruntime-web/dist/esm/ort.min.js 1801:29786-29793
Module not found: Error: Can't resolve 'process/browser' in '/home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/esm'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
resolve 'process/browser' in '/home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/esm'
  Parsed request is a module
  using description file: /home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/esm/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/esm/node_modules doesn't exist or is not a directory
      /home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/dist/node_modules doesn't exist or is not a directory
      /home/bricklayer/Workspace/segment-anything/demo/node_modules/onnxruntime-web/node_modules doesn't exist or is not a directory
      /home/bricklayer/Workspace/segment-anything/demo/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/bricklayer/Workspace/segment-anything/demo/node_modules
        existing directory /home/bricklayer/Workspace/segment-anything/demo/node_modules/process
          using description file: /home/bricklayer/Workspace/segment-anything/demo/node_modules/process/package.json (relative path: .)
            using description file: /home/bricklayer/Workspace/segment-anything/demo/node_modules/process/package.json (relative path: ./browser)
              Field 'browser' doesn't contain a valid alias configuration
              /home/bricklayer/Workspace/segment-anything/demo/node_modules/process/browser doesn't exist
      /home/bricklayer/Workspace/segment-anything/node_modules doesn't exist or is not a directory
      /home/bricklayer/Workspace/node_modules doesn't exist or is not a directory
      /home/bricklayer/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
 @ ./src/App.tsx 5:0-51 36:36-59
 @ ./src/index.tsx 8:0-24 12:24-27

ERROR in ./node_modules/onnxruntime-web/dist/esm/ort.min.js
Cannot read properties of undefined (reading 'module')
TypeError: Cannot read properties of undefined (reading 'module')
    at ProvidedDependencyTemplate.apply (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/dependencies/ProvidedDependency.js:134:61)
    at JavascriptGenerator.sourceDependency (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/javascript/JavascriptGenerator.js:221:12)
    at JavascriptGenerator.sourceModule (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/javascript/JavascriptGenerator.js:112:9)
    at JavascriptGenerator.generate (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/javascript/JavascriptGenerator.js:98:8)
    at NormalModule.codeGeneration (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/NormalModule.js:1209:22)
    at /home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/Compilation.js:3345:22
    at /home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/Cache.js:91:34
    at Array.<anonymous> (/home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/cache/MemoryCachePlugin.js:45:13)
    at /home/bricklayer/Workspace/segment-anything/demo/node_modules/webpack/lib/Cache.js:91:19
    at Hook.eval [as callAsync] (eval at create (/home/bricklayer/Workspace/segment-anything/demo/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:19:1)
 @ ./src/App.tsx 5:0-51 36:36-59
 @ ./src/index.tsx 8:0-24 12:24-27
jmuham commented

add this entire block to demo/configs/webpack/common.js

      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      },

Adding a 'rules' block in demo/configs/webpack/dev.js worked for me.

module.exports = merge(commonConfig, {  // Find this line in dev.js
  module: {
    rules: [ // Add this block
      { resolve: {
        fullySpecified: false,
        } 
      }
    ]
.....

Thank you! Works for me.

add this entire block to demo/configs/webpack/common.js

      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      },

works for me. Thanks!