Resolving template string interpolation at run-time, not at bundle creation time - javascript

I have a JavaScript application that is bundled into a client-side application and run in the browser.
An old version of the application used to have a variable assignment like this:
const API_ROOT_URL = `http://${window.location.hostname}:8000/`;
This would presumably get interpolated in the browser.
However, this code now throws a webpack error on webpack 4.42.0:
ReferenceError: window is not defined
at Object.<anonymous> (/usr/src/app/src/client_config.js:4:32)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/usr/src/app/webpack.config.js:1:99)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
at requireConfig (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
at /usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:71:45
at Object.parse (/usr/src/app/node_modules/yargs/yargs.js:567:18)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/usr/src/app/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/usr/src/app/node_modules/webpack/bin/webpack.js:156:2)
It seems that the interpolation is happening at the time the bundle is created, when window doesn't exist.
Can I get the intended behavior?

Related

optional chaining operator in node modules not working in linux

this is the error i am facing when i try to run the code
const contentType = response?.headers['content-type'];
SyntaxError: Unexpected token .
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/home/pranav/mona/monacip-backend/node_modules/#api.video/nodejs-client/lib/index.js:15:38)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
this ?. operator is not working on ubuntu machines

better-sqlite3 different nodejs version using error replit

/home/runner/stoneclane/node_modules/bindings/bindings.js:121
throw e;
^
Error: The module '/home/runner/stoneclane/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
the module (for instance, using npm rebuild or npm install).
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1185:18)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at bindings (/home/runner/stoneclane/node_modules/bindings/bindings.js:112:48)
at new Database (/home/runner/stoneclane/node_modules/better-sqlite3/lib/database.js:48:64)
at Object. (/home/runner/stoneclane/node_modules/quick.db/src/index.js:7:15)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/home/runner/stoneclane/node_modules/quick.db/index.js:7:18)
at Module._compile (node:internal/modules/cjs/loader:1103:14) {
code: 'ERR_DLOPEN_FAILED'
}
exit status 1

it gives "SyntaxError: Unexpected token" when importing express-handlebars

when I add this line error appears and if removed error disappears
const expressHandleBars = require('express-handlebars');
This is the error,
C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\lib\express-handlebars.js:230
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\index.js:9:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
What version of Node.js are you using? Please check this issue.
The error cause by Trailing commas in function call feature. This feature had been implemented in Node v8 so you have to upgrade your Node.js to version 8+ to be able to use express-handlebars.

Meteor JS 1.3 errors loading isopacket "ddp"

I am trying to get into MeteorJS and learn how it works, however after installing a fresh copy of MeteorJS 1.3 and creating a project, I am always met with the error below.
I've been searching through Google for a while now and I can't come across anyone with the same problem, which is odd because this is a completely fresh installation.
Errors prevented isopacket load:
While loading isopacket `ddp`:
module.js:338:15: Cannot find module './_baseClone'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-types\node_modules\lodash\clone.js:1:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-types\lib\index.js:314:38)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-template\lib\index.js:84:43)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\lib\index.js:525:46)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object._.extend.Npm.require (C:\tools\isobuild\bundler.js:1570:22)
at Object.require (C:\tools\isobuild\bundler.js:1547:11)
at Package (packages/babel-compiler/babel-compiler.js:17:1)
at packages/babel-compiler/babel-compiler.js:356:1
at packages/babel-compiler/babel-compiler.js:356:1
You on Windows 7 or 10 I presume?
I think they broke it with their latest v1.3.3 update today. I am having the exact same issues off brand new installs. Things used to work in v1.3.2 and I am unsure on how to fix this for v1.3.3 yet.
Theoretically though, you can try running it off an older build. Try this.
meteor create myApp --release 1.3.2.4
cd myApp
meteor
It will probably take a really long time to initially create the app, but when it finally finishes it should work. Just don't do "meteor update" on it for now.

Module version mismatch

bcrypt seems like has mismatch with node.
my node version is 4.2.1
Error: Module version mismatch. Expected 46, got 14.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at bindings (/opt/app/app/node_modules/bcrypt/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/opt/app/app/node_modules/bcrypt/bcrypt.js:3:35)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/opt/app/app/controllers/account.js:10:14)
at Module._compile (module.js:435:26)
You (typically) have to recompile addons when switching between "major" versions of node (e.g. v0.10, v0.12, 4.0, 5.0, etc). So an npm rebuild should do just this for you.

Categories

Resources