How to get external package version from package.json - reactjs

I am trying to get the version number of an external package like this:
import * as packageInfo from "<package_name>/package.json";
...
console.log(packageInfo.version);
There is no error in code editor, but my build fails with error:
Module not found: Error: Package path ./package.json is not exported from package
But I can see the package.json in node_modules respective package folder. Any idea what could be wrong here?

Related

React Module not found

I have installed an npm package on my react application but everytime I try to compile I get this error:
Module not found: Error: Can't resolve 'serialport' in 'C:\Users\Username\Desktop\ProjectGroup\c-test\src'
I have checked the node_modules folder and it is in fact in that folder.
i have also tried to install it again but it still throws the same error.
How would I go about fixing this?
As shown in comments, you installed only the types which are usefull for TypeScript.
Run npm i serialport

Vite esbuild failing for old Non-ESM package

I'm trying to use glsl-transpiler(https://github.com/stackgl/glsl-transpiler) with my vite project but am running into issues with esbuild, which outputs
[ERROR] [plugin vite:dep-pre-bundle] Failed to resolve entry for package "escaper". The package may have incorrect main/module/exports specified in its package.json.
Adding optimizeDeps: {exclude:['glsl-transpiler']} to defineConfig in vite.config.js allows the app to build, but I get a require is not defined error when I try to use the package due to the https://github.com/stackgl/glsl-transpiler/blob/master/index.js ll:8.
Does anyone know how I can successfully use this old package and its old dependencies in my project?

Unable to resolve published NPM module in project

I recently published a simple React module that I wrote in TypeScript. I tested my module by importing the local package into a project, and it worked flawlessly. However, now that I've published the module, whenever I try to import it into a project, I get the following error:
Failed to compile.
./src/...
Module not found: Can't resolve '<module>' in '.../src/...'
Package is listed in both package.json and package-lock.json, and the module shows up in node_modules. Additionally, VS Code doesn't throw any fits, so I'm not quite sure what could be the issue.
NPM, being the "Node Package Manager" interprets packages as node modules. in the documentation, it says it will try to load a folder by looking for a package.json file, and resolving the path in main relative to the folder it found.
So when publishing a package with a build step, always make sure to build it before its published (there is a prepublish hook for this, in the scripts object in package.json).
The other thing is to make sure that the package being published refers to the correct main, bin (if applicable), and module (if applicable) paths in the package.json file. if the source file is src/mylib.coffee and the built file is dist/mylib.js, the package.json must contain { "main": "dist/mylib.js" } in order that someone installing this module as a dependency into their node_modules folder would require the correct file.
in short make sure "main" in package.json points to the right file!

React Package is not getting loaded from node-modules

I have created the package for learning purpose nik-drop presently available in npm.
now testing purpose I tried to use that package in my another demo project but when I try to use this package from npm-moduls. I unable to access that package.
Even through Package is available in node-module folder.
import DropDownMob from 'nik-drop';
I'm getting error
Module not found: Can't resolve 'nik-drop' in '/home/nikhil/Documents/React-Project/sec/sec/src'
This is not node module path, react trying to access it from local directory.
How can I resolve it.

react-bootstrap-table missing module error upon startup

When I try to run the client dev server, it bombs out with the following message:
Module not found: Error: Cannot resolve module 'react-dom/lib/getVendorPrefixEventName in: c:....ReactTransitionEvents.js
When I locate ReactTransitionEvents.js on my hard drive and look at it, I can see a require statement for getVendorPrefixEventName:
var getVendorPrefixedEventName = require('react-dom/lib/getVendorPrefixedEventName');
Is this looking for the lib folder in the react-dom folder in the main node_modules folder?

Resources