Reputation: 440
I recently published an npm module https://www.npmjs.com/package/splashup-widget.
I tried to install it in a 'create-react-app' sample app, but I got an error Cannot find module 'splashup-widget'
this is the webpack config:
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: /\.jsx?$/,
exclude: /(node_modules)/,
use: 'babel-loader'
}
]
},
externals: {
react: "react"
}
}
This is a React code:
import logo from './logo.svg';
import './App.css';
import Quiz from 'splashup-widget'
function App() {
return (
<div className="App">
<Quiz />
</div>
);
}
export default App;
I checked this question: How to build an npm package so it is able to be imported/required but it seems that it's not my case, since both entry and output filenames are 'index.js'.
Would greatly appreciate any help :-)
Upvotes: 1
Views: 2525
Reputation: 1695
The main
field in your package's package.json
is incorrect; you should change it from index.js
to build/index.js
.
Upvotes: 1