-
Notifications
You must be signed in to change notification settings - Fork 257
Closed
Description
Due to dynamic require of stores, esbuild cannot bundle nconf. See following warning when bundling with esbuild:
> ../node_modules/nconf/lib/nconf.js:28:15: debug: This call to "require" will not be bundled because the argument is not a string literal
28 │ return require('./nconf/stores/' + store)[name];
Since the list of builtin stores is static, they're is no need to make dynamic require.
Possible workaround: specify an esbuild inject scripts, eg esbuild --bundle --inject:esbuild-inject.js src/index.js
with esbuild-inject.js
import nconf from 'nconf';
import { Argv } from 'nconf/lib/nconf/stores/argv';
import { Env } from 'nconf/lib/nconf/stores/env';
import { File } from 'nconf/lib/nconf/stores/file';
import { Literal} from 'nconf/lib/nconf/stores/literal';
import { Memory} from 'nconf/lib/nconf/stores/memory';
// avoid dynamic require() in nconf
Object.defineProperty(nconf, 'Argv', { get: () => Argv });
Object.defineProperty(nconf, 'Env', { get: () => Env });
Object.defineProperty(nconf, 'File', { get: () => File });
Object.defineProperty(nconf, 'Literal', { get: () => Literal});
Object.defineProperty(nconf, 'Memory', { get: () => Memory});
export { nconf };
However it would be more convenient to avoid that.
adenhertog, catamphetamine and kahluagenie
Metadata
Metadata
Assignees
Labels
No labels