question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to fix my code when I call the url in the json file?

See original GitHub issue

I 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;

  1. 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 ''

  2. 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'

  1. 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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
YusufOzturk-Developmentcommented, Aug 10, 2022

@rwoll I got it and try in 30 minutes

0reactions
YusufOzturk-Developmentcommented, Aug 10, 2022

@rwoll worked, thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON file coming up fine from the URL but wont allow me to ...
You're specifying JSON as the format for that api, when you should be specifying JSONP. See the api documentation. To fix it just...
Read more >
Loading JSON data from a URL (Asynchronous ... - YouTube
The first step is just using a URL instead of a local JSON file. How does this change your code ? How do...
Read more >
JSON editing in Visual Studio Code
Edit JSON files in Visual Studio Code. ... Formatting. You can format your JSON document using Ctrl+Shift+I or Format Document from the context...
Read more >
JSON Online Validator and Formatter - JSON Lint
JSONLint is an online editor, validator, and reformat tool for JSON, which allows you to directly type your code, copy and paste it,...
Read more >
Using the Fetch API - MDN Web Docs
Supplying request options · Sending a request with credentials included · Uploading JSON data · Uploading a file · Uploading multiple files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found