Open K1vs opened 7 months ago
I downgraded the version with npm install @microsoft/iot-cardboard-js@v1.0.0-beta.235
and it worked
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)
@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"),
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
After successful code compilation, I am also getting error like "_microsoft_iot_cardboard_js__WEBPACK_IMPORTED_MODULE_3__.k is not a constructor" @lotus-2601 do you know how to resolve?
The application cannot be launched after including this library. Initially we get a problem of this type.
Full text of problem: initial_iot_error.txt
This can be fixed by adding a plugin node-polyfill-webpack-plugin to the webpack. (Using Craco, react-app-rewired or react-scripts eject) E.g.
But then I get a new problem:
And fix it using fallback:
But unfortunately, a new problem arises, and I can no longer solve it.
The last problem also occurs if I use the template https://github.com/Azure-Samples/cra-template-iot-cardboard-js.
At the moment, the use of this library is completely blocked. Which significantly reduces the attractiveness of Azure as a platform for building digital twins.