After taking an build, install the npm package to my new created react app using npm i ../. And imported the component in App.js. But it shows the error that Module not found: Can't resolve 'test-app-npm'. But it's installed in package.json like this "test-app-npm": "file:../testnpm".
created package folder name:"testnpm", created react app folder name:"testapp"
webpack.config.js
var path = require("path");
module.exports = {
mode: "production",
entry: "./src/index.js",
output: {
path: path.resolve("build"),
filename: "index.js",
libraryTarget: "commonjs2",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
externals: {
react: "react",
},
};
package.json
{
"name": "test-app-npm",
"version": "1.0.0",
"description": "test react app npm release",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/preset-react": "^7.16.0",
"babel-loader": "^8.2.3",
"css-loader": "^6.5.0",
"style-loader": "^3.3.1",
"webpack": "^5.61.0",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"react": "^17.0.2"
},
"author": "",
"license": "ISC"
}