Alternative extensions not getting picked up by the loader?
Panoplos opened this issue · comments
Hello, I have json files with the extension .schema
that I am attempting to load in a webpack build. The relevant webpack configuration bits are as follows:
...
resolve: {
...
extensions: ['.js'],
modules: [path.join(root, 'src'), 'node_modules']
},
module: {
rules: [
{
test: /\.(json|schema)$/,
use: [{ loader: 'json-loader' }]
},
...
}
}
So, in a source file, when I import .json
modules, there is no issue, but when I import a file with the .schema
extension, it seems to be parsed by babel, instead, like follows:
const BlockedInfo = require('server/store/schemas/blockedinfo.schema')
1503033073253 - Origin: Worker (PID 13508)
[Error] SyntaxError: /home/Panoplos/Documents/Development/Node.js/testing-schema/src/server/store/schemas/blockedinfo.schema: Unexpected token, expected ; (2:6)
1 | {
> 2 | "$id": "/BlockedInfo",
| ^
3 | "type": "array",
4 | "items": {
5 | "type": "object",
at Parser.pp$5.raise (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:4443:13)
at Parser.pp.unexpected (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1755:8)
at Parser.pp.semicolon (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1736:38)
at Parser.pp$1.parseExpressionStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2230:8)
at Parser.parseExpressionStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5817:20)
at Parser.pp$1.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1905:17)
at Parser.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5795:22)
at Parser.pp$1.parseBlockBody (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2262:21)
at Parser.pp$1.parseBlock (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2241:8)
at Parser.pp$1.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1862:19)
at Parser.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5795:22)
at Parser.pp$1.parseBlockBody (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2262:21)
at Parser.pp$1.parseTopLevel (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1772:8)
at Parser.parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1667:17)
at parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:7163:37)
at File.parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babel-core/lib/transformation/file/index.js:517:15)
1503033073290 - Worker 0 exited - Exit code: 1
Any insights as to why this may be happening will be greatly appreciated.
@Panoplos very interesting, maybe something invalid in blockedinfo.schema
, can your provide minimum test repo?
No, as the schema is loaded fine when I change the extension to .json
. I'll see what I can do on the minimal test repo.
OK, I figured out what is wrong, and it is quite embarrassing. LOL
I am running the server for dev mode directly from babel, not via the webpack build, so of bloody course these settings are not helping anything.
So, it brings me to a question...how would someone go about using this loader without webpack? Or is it possible to direct babel to see alternate extensions as json files?