Re-introduce main field to package.json #517
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I believe we should add "main" field to the
package.json
for this repository. This will also need to be done for the dependency "steno" which is in a PR here. The version in both this and steno's PR have been bumped as a patch, and this PR now references that patch of steno.Why
Aside from the fact that nodejs.org advises to do so here...
I'm also having trouble importing LowDB in a common project: a Create React App project. I presume the real problem is with Create React App's usage of Webpack 5, and it seemingly ignoring (or not properly implementing) the
"exports"
field in a module'spackage.json
.Recreating the issue is easy...
src/index.ts
:Command fails with:
The reason is that Webpack doesn't know how to find the package when it is bundling everything together. Running
yarn list lowdb
is a false-positive.Testing the fix...
Simply find
lowdb
in thenode_modules
of themy-app
CRA that you've just created and add"main": "./lib/index.js"
. You will also need to do the same withsteno
.Then run
yarn build
and all is well...Win win
I think this is a pretty straight forward addition and will probably help a lot of people out who are using Webpack to bundle.
There is a hack which is to use LowDB by importing the
lib
subdirectory (import { Low } from 'lowdb/lib
), but this isn't sufficient when you're bundling other modules that do have the correct import syntax and a good bundler. So a big monorepo project suffers. So I think it's just easier/safer to include a "main" field inpackage.json
.Until this is resolved I will have to use a forked version of this library, and
steno
, which is a shame.