Require optional files
See original GitHub issueI 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:
- Created 8 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you re-open at Stack Overflow for more ideas?
Technically you could push the problem to configuration side now and perform aliasing there after you check.