Code Monkey home page Code Monkey logo

Comments (4)

K1vs avatar K1vs commented on May 24, 2024 1

I was able to solve the problem; to do this I had to add these polyfills. And installed the packages corresponding to these polyfills.

module.exports = {
  webpack: {
    configure: (config, { env, paths }) => {
      const fallback = config.resolve.fallback || {};
      Object.assign(fallback, {
        assert: require.resolve("assert"),
        buffer: require.resolve("buffer"),
        console: require.resolve("console-browserify"),
        constants: require.resolve("constants-browserify"),
        crypto: require.resolve("crypto-browserify"),
        domain: require.resolve("domain-browser"),
        events: require.resolve("events"),
        http: require.resolve("stream-http"),
        https: require.resolve("https-browserify"),
        os: require.resolve("os-browserify/browser"),
        path: require.resolve("path-browserify"),
        punycode: require.resolve("punycode"),
        process: require.resolve("process/browser"),
        querystring: require.resolve("querystring-es3"),
        stream: require.resolve("stream-browserify"),
        string_decoder: require.resolve("string_decoder"),
        sys: require.resolve("util"),
        timers: require.resolve("timers-browserify"),
        tty: require.resolve("tty-browserify"),
        url: require.resolve("url"),
        util: require.resolve("util"),
        vm: require.resolve("vm-browserify"),
        zlib: require.resolve("./szlib"),
        fs: false,
      });

      config.resolve.fallback = fallback;
      config.plugins = (config.plugins || []).concat([]);
      return config;
    },
  },
};

Pay attention to line zlib: require.resolve("./szlib"),
Content of file szlib.js

"use strict";

const bzlib = require("browserify-zlib");

const zlib = bzlib;

zlib.constants = zlib; //TODO select only constants

Object.assign(exports, zlib);

without this we will have an error

ERROR
Cannot read properties of undefined (reading 'Z_SYNC_FLUSH')
TypeError: Cannot read properties of undefined (reading 'Z_SYNC_FLUSH')
    at ./node_modules/@microsoft/iot-cardboard-js/internal/axios-1bc8e67b.js (http://localhost:3000/static/js/bundle.js:666676:67)
    at options.factory (http://localhost:3000/static/js/bundle.js:880420:31)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:879813:33)
    at fn (http://localhost:3000/static/js/bundle.js:880077:21)
    at ./node_modules/@microsoft/iot-cardboard-js/internal/HierarchyNode-05d12d93.js (http://localhost:3000/static/js/bundle.js:63903:76)
    at options.factory (http://localhost:3000/static/js/bundle.js:880420:31)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:879813:33)
    at fn (http://localhost:3000/static/js/bundle.js:880077:21)
    at ./node_modules/@microsoft/iot-cardboard-js/internal/ADT3DSceneAdapter-0423f1cf.js (http://localhost:3000/static/js/bundle.js:16630:84)
    at options.factory (http://localhost:3000/static/js/bundle.js:880420:31)

from iot-cardboard-js.

lorenpelli avatar lorenpelli commented on May 24, 2024

I downgraded the version with npm install @microsoft/[email protected] and it worked

from iot-cardboard-js.

lotus-2601 avatar lotus-2601 commented on May 24, 2024

@K1vs Thanks for recommending the corresponding polyfills. It resolved the dependency errors to a great extent, but I found one more error on my terminal, when using this as a template in my React app.
I am using node v16.

Module not found: Error: Can't resolve 'process/browser' in 'C:\Users\0007CI744\Documents\Projects\cardboard-demo\node_modules@headlessui\react\dist\components\combobox'
Did you mean 'browser.js'?

For anyone else facing this, please note I had to make the below additions to my config-overrides.js
config.module.rules.unshift({ test: /\.m?js$/, resolve: { fullySpecified: false, // disable the behavior }, });
and to the fallback object, I added
"process/browser": require.resolve("process/browser"),

from iot-cardboard-js.

lotus-2601 avatar lotus-2601 commented on May 24, 2024

After successful code compilation, I am getting this error on my browser. Any idea, how to fix this?

Uncaught TypeError: util__WEBPACK_IMPORTED_MODULE_0__.TextEncoder is not a constructor

from iot-cardboard-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.