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.

Require optional files

See original GitHub issue

I want to require localConfig.js which in .gitignore and can not exist on particular machine. For the server side code there is a try-catch hook:

var local = {}; // default value
try {
        local = require('./local');
    }
} catch (e) {
    // file not found
}

But webpack will log a warning anyway:

WARNING in ./config/serverConfig.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./local in /Users/dm.kuznetsov/square/config

I cannot use fs, because my code is isomorphic.

How can I require a file, which can not exist properly?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bebrawcommented, Dec 24, 2016

Can you re-open at Stack Overflow for more ideas?

0reactions
bebrawcommented, Apr 21, 2017

Technically you could push the problem to configuration side now and perform aliasing there after you check.

Read more comments on GitHub >

github_iconTop Results From Across the Web

optional-require
NodeJS Require that let you handle module not found error without try/catch. Latest version: 1.1.8, last published: a year ago.
Read more >
jchip/optional-require
Optional Require. node.js require that let you handle module not found error without try/catch. Allows you to gracefully require a module only if...
Read more >
optional-require v1.1.8
node.js require that let you handle module not found error without try/catch. Allows you to gracefully require a module only if it exists...
Read more >
requiring optional javascript files with requirejs (e.g. ...
This particular style allows the modules to load either through require or direct script inclusion. I modified it slightly to set up the...
Read more >
Required and Optional Header Files
The description of each run-time routine includes a list of the required and optional include, or header (.H), files for that routine.
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