I have a very simple webpack loader that transforms a csv file (that has already been parsed by csv-loader) and processes any markdown in the csv's description field:
var md = require("markdown-it")()
module.exports = function (csvData) {
let newCSVdata = eval(csvData)
.map(x => ({...x, Description: md.renderInline(x.Description)}))
return `export default ${JSON.stringify(newCSVdata)}`
}
When I start the simple project, with webpack serve the resource is properly built. However, if I make any changes to the CSV and save them, webpack immediately fails and I get:
ERROR in ./data.csv
Module build failed (from ./markdown-loader.js):
LoaderRunnerError: Module '[PATH TO markdown-loader.js]' is not a loader (must have normal or pitch function)
Stopping webpack and restarting it causes the problem to resolve and the csv is properly processed again.
Here is the webpack config:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
mode: "production",
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
compress: true,
port: 9000,
},
module: {
rules: [
{
test: /\.csv$/,
use: [
{ loader: path.resolve("./markdown-loader.js") },
{
loader: 'csv-loader',
options: {
dynamicTyping: true,
header: true,
skipEmptyLines: true
}
}
]
}
]
}
};
Is there something special that needs to be done to the loader to ensure it works when the resource is reloaded?