Code Monkey home page Code Monkey logo

Comments (18)

jrmyio avatar jrmyio commented on June 10, 2024 2

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.

vitalyster avatar vitalyster commented on June 10, 2024 2

@lorenwest Yes, we are using it server-side, target: node to bundle app into single file without node_modules

from node-config.

DeutscherDude avatar DeutscherDude commented on June 10, 2024 1

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.

cbazureau avatar cbazureau commented on June 10, 2024

Same here !

from node-config.

markstos avatar markstos commented on June 10, 2024

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.

cbazureau avatar cbazureau commented on June 10, 2024

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.

cbazureau avatar cbazureau commented on June 10, 2024

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.

davo3078 avatar davo3078 commented on June 10, 2024

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.

I have the same problem

from node-config.

vitalyster avatar vitalyster commented on June 10, 2024

Same issue with webpack and target: 'node'

from node-config.

markstos avatar markstos commented on June 10, 2024

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.

lorenwest avatar lorenwest commented on June 10, 2024

from node-config.

markstos avatar markstos commented on June 10, 2024

Related:

from node-config.

shayded-exe avatar shayded-exe commented on June 10, 2024

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.

lorenwest avatar lorenwest commented on June 10, 2024

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.

lorenwest avatar lorenwest commented on June 10, 2024

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.

DeutscherDude avatar DeutscherDude commented on June 10, 2024

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.

lorenwest avatar lorenwest commented on June 10, 2024

Surely there are other NPM packages with dependencies (yes, an understatement). What does webpack do with those?

from node-config.

cbazureau avatar cbazureau commented on June 10, 2024

For webpack it's simple, as i said earlier, two issues :

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.