I am currently in the process of developing a small npm library to streamline API interaction. Here is an overview of my folder structure...
dist/
index.js
src/
index.js
endpoints/
endpoint1.js
package.json
webpack.config.js
Inside my src/index.js file, I have...
import {endpoint1} from './endpoints'
module.exports = class lib {
...
}
When running npm run build (which executes webpack --display-error-details --mode production), webpack throws a significant error stating "Module not found: Error: Can't resolve './endpoints' in 'my\project\dir\src'.
My current webpack.config.js file looks like this...
const path = require('path');
module.exports = {
mode: 'production',
entry: path.join(__dirname, '/src/index.js'),
output: {
path: path.resolve('dist'),
filename: 'index.js',
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /.js?$/,
exclude: /(node_modules)/,
use: 'babel-loader'
}
]
},
resolve: {
modules: [
path.resolve(__dirname, 'src/endpoints')
],
extensions: ['.js']
}
};
I've noticed similar questions asked in the past, and the suggested solutions haven't worked for me so far. I'm posting this in case I'm missing something obvious. Feel free to ask for more information if needed! Apologies for the lengthy text. Thank you.