raw-loader
errors out when attempting to require any .md
file.
Adding raw loader to import markdown files:
test: /\.md$/i,
use: [{
loader: 'raw-loader',
options: {
esModule: false
}
}],
In .js
file, require the markdown file..
return require(postPath)
// postPath is '../posts/awards.md'
Error: Cannot find module '../posts/awards.md'
at webpackEmptyContext (eval at <path to file>)
....
the path to markdown file is the relative path: /posts/awards.md
If I change awards.md
to awards.json
it works. So maybe it is an issue with raw-loader
looking for a export
in awards.md
and not find one, thus erroring out? Isn't the point of esModule: false
to instruct Webpack to NOT treat it as module?
Seems like you're having the same problem as this person.
Quoting an answer:
I re-created your problem and sure enough:
Doesn't work. HOWEVER this works:
So it should suffice to change your code to this:
And change
postPath
to: