Comments (18)
Same problem here.
I am using esbuild to build a project with that uses config
and ran into Error: Cannot find module 'json5'
after running the build.
The build is supposed to work without a node_modules
folder.
from node-config.
@lorenwest Yes, we are using it server-side, target: node
to bundle app into single file without node_modules
from node-config.
Hello There :)
Reverting the changes seems plausible considering the issues it has caused to folks using webpack and other bundlers.
I am rather certain, that we will go back to having issues with parsing comments though.
The exact problem is already at hand, namely the RegExp that was not properly parsing data from JSON.
Changing it is possible, but will require, in my opinion, a lot of additional testing for all special characters, different alphabets, etc.
I would again be happy to be of aid, but my time this week is rather limited.
from node-config.
Same here !
from node-config.
3.3.10 lists json5
as a dependency. Therefore, json5
should always be installed.
How did you manage to install or upgrade node-config
3.3.10 without ending up with the json5
dependency installed?
from node-config.
hello @markstos, I'm using yarn 1.x and weback to 5.89.0. json5 is installed (was already installed by another dep in my case)
To make in work I need to replace in parser.js :
JSON5 = require(JSON5_DEP);
by
JSON5 = require('json5').default;
- Explicit require (
require('json5')
) is needed for webpack https://stackoverflow.com/a/42804941 - i also need
.default
otherwise i get a "JSON5.parse is not a function". I need to investigate this point (not clear to me)
This issue was previously masked to me because native JSON.parse was doing the job (0058701)
from node-config.
Ok the workaround for me was to exclude node_modules from the bundle (you can use https://www.npmjs.com/package/webpack-node-externals externals: [nodeExternals()]
for example) and to ship node_modules with the build.
from node-config.
Same problem here.
I am using esbuild to build a project with that uses
config
and ran intoError: Cannot find module 'json5'
after running the build.The build is supposed to work without a
node_modules
folder.
I have the same problem
from node-config.
Same issue with webpack
and target: 'node'
from node-config.
I'd say this is a webpack issue. Search the issues and PRs for webpack for past and current problems with that environment.
from node-config.
from node-config.
Related:
from node-config.
Regardless, I think node-config
should be able to work without json5
and fallback to JSON.parse
if it doesn't exist.
from node-config.
We have the choice of reverting the last changes or having someone move this forward to resolve both issues. @DeutscherDude was the champion of the last changes - would you like to offer an opinion?
from node-config.
Webpack is a bundler, and I don't know much about it except for seemingly infinite configurability. Wouldn't a bundler be able to, you know, bundle dependencies?
Is this a webpack-only issue, or are there rollup, etc. bundlers that have the same problem? Could we put some magic-sauce in the code to tell bundlers to bundle, which doesn't break non-bundler users?
from node-config.
I had rather little exposure to webpack.
If folks would like to provide some minimal code to reproduce these issue, it would be great for debugging purposes.
from node-config.
Surely there are other NPM packages with dependencies (yes, an understatement). What does webpack do with those?
from node-config.
For webpack it's simple, as i said earlier, two issues :
- Issue 1 : https://stackoverflow.com/a/42804941 : it can't resolve (during bundling time) syntax like
require(dynamic_var)
. Webpack can resolve simple pattern likerequire(`./locale/${dynamic_var}.json`)
https://webpack.js.org/guides/dependency-management/#require-with-expression by bundling every file that match the pattern. - Issue 2 : json5/json5#240 : json5 + webpack have issues with default export
So if webpack-node-externals is not an option for some of you, for me node-config is mainly a node lib (not bundle sized driven) or, if used in browser, it will use json config. So the simple solution can be to hard code json5 require at the top of parser.js
like this :
// webpack can't solve dynamic module
// @ref https://webpack.js.org/guides/dependency-management/#require-with-expression
const JSON5Module = require('json5');
// webpack resolves json5 with module field out of the box which lead to this usage
// @ref https://github.com/json5/json5/issues/240
const JSON5 = JSON5Module.default || JSON5Module;
I suggest something like this : #757 (tested on my side with and without webpack-node-externals)
At the end 3 kinds of people :
- Node users with webpack-node-externals => no change for them
- Node users that without webpack-node-externals and use JSON config format (if they used something else, like YAML, they already had an issue) => fix the problem
- Browser users (99% chance of using json format) => fix the problem (bundling json5 is now required anyway because you choose this lib as the "official parser" for node-config)
from node-config.
Related Issues (20)
- custom-environment-variables.json says variable is not defined. HOT 1
- Feature Request: First class Kubernetes secret files support HOT 3
- [BUG] Cypress component testing fails with error `<CONFIG_VARIABLE> is not defined`
- Deal With Async Properties in DeferConfig HOT 1
- [BUG] Documentation is missing HOT 4
- [BUG] custom-environment-variables file does not support cjs extension HOT 2
- [BUG] Extra quotes on config file broke app HOT 5
- Cannot use defer with esbuild (fix: export defer from config) HOT 1
- Unable to use
- [BUG] Configuration files with different extensions and APP_INSTANCE not loaded in the right order HOT 2
- [BUG] Javascript getters calling during config initialization
- [BUG] Empty key in YAML sets value to null HOT 2
- [BUG] Environment variable substitution fails silently if "__format" parser is not supported HOT 1
- Project breaks after updating ts version (using .cjs config files)
- Disable some "defaults", like local.{ext} loading HOT 3
- [BUG] node-config package.json has not all the parsers available installed as production dependencies HOT 6
- [BUG] YAML binary type is mangled
- [BUG] Encoungering an unexpected ENOTDIR while trying to open non-existing runtime.json
- [BUG] DeprecationWarnings in node v22 DEP0055 DEP0047 DEP0044
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-config.