How to fix my code when I call the url in the json file?
See original GitHub issueI have a dev.json file;
{
"env": {
"url": "http://test.co"
}
}
I want to use this json file as a config file.In my project I m calling the url like below;
const config = require(process.env.CONFIG || '');
const { url } = { url: config.url };
In the package.json file,I m running below script;
npx cross-env CONFIG=dev.json npx playwright test test.spec.ts && npx playwright test id.spec.ts;
But got error related to call url in the dev.json.I tried 3 different code like below;
-
When I type the below code in the project,
const config = require(process.env.CONFIG || ''); const { url } = { url: config.url };Took below error in the terminal output;
TypeError: The argument 'id' must be a non-empty string. Received '' -
When I type the below code in the project,
const config = require(`${process.env.CONFIG }`);
const { url } = { url: config.url };
Took below error in the terminal output
Error: Cannot find module 'undefined'
-
When I type the below code in the project,I gives an error on the code ,
const config = require(process.env.CONFIG);Error on the code is below;
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
How to call url in the dev.json. How to fix my code on the require(process.env.CONFIG) side when I call the url in the dev.json?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
@rwoll I got it and try in 30 minutes
@rwoll worked, thanks