I encountered an error while trying to load an HTML file in the JavaScript console of the Brave browser. The error message reads:
require.js:5 Uncaught Error: Module name "constants.js" has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded
at makeError (require.js:5)
at Object.s [as require] (require.js:5)
at requirejs (require.js:5)
at flatbuffers.js:4
Here are more details on the issue:
I am developing an HTML page that requires several *.js files, all of which are installed locally.
The specific JavaScript file I need is "flatbuffers.js," and it is located in the root directory of my project under "project/node_modules/flatbuffers/js/*". The version of this file is 2.0.6.
My project also relies on "require.js," which I downloaded from this source.
Below is the structure of my project directories:
project/
- 3rdparty/
- js/
- require.js
- docs/
- index.html
- node_modules/
- flatbuffers/
- js/
*.js (all relevant flatbuffer JS files)
The contents of my "project/docs/index.html" file are as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title</title>
<link type="text/css" rel="stylesheet" href="styles.css">
</head>
<body>
<script src="../3rdparty/js/require.js"></script>
<!-- Generated flatbuffer schema -->
<script>var exports = {};</script>
<script src="../node_modules/flatbuffers/js/flatbuffers.js"></script>
</body>
</html>
It's worth noting that the "constants.js" file is indeed present in the "project/node_modules/flatbuffers/js/" directory. The other files in the same directory include:
builder.d.ts
builder.js
byte-buffer.d.ts
byte-buffer.js
constants.d.ts
constants.js
encoding.d.ts
encoding.js
flatbuffers.d.ts
flatbuffers.js
flexbuffers
flexbuffers.d.ts
flexbuffers.js
README.md
types.d.ts
types.js
utils.d.ts
utils.js
I'm struggling to understand why "constants.js" fails to load and causes the error mentioned above.
If it helps, here is the content of the "flatbuffers.js" file:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ByteBuffer = exports.Builder = exports.Encoding = exports.isLittleEndian = exports.float64 = exports.float32 = exports.int32 = exports.SIZE_PREFIX_LENGTH = exports.FILE_IDENTIFIER_LENGTH = exports.SIZEOF_INT = exports.SIZEOF_SHORT = void 0;
var constants_js_1 = require("./constants.js");
Object.defineProperty(exports, "SIZEOF_SHORT", { enumerable: true, get: function () { return constants_js_1.SIZEOF_SHORT; } });
var constants_js_2 = require("./constants.js");
Object.defineProperty(exports, "SIZEOF_INT", { enumerable: true, get: function () { return constants_js_2.SIZEOF_INT; } });
...
Specifications of my setup:
$ uname -a
Linux khz 5.8.0-43-generic #49~20.04.1-Ubuntu SMP Fri Feb 5 09:57:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ node --version
v17.6.0
$ npm --version
8.5.1
For reference, I launched Brave using:
brave-browser --allow-file-access-from-files
Any assistance would be highly appreciated.