Could not resolve 'package.json'
garyb opened this issue · 3 comments
This one is probably a lot more dodgy than #14 even, but I thought I'd mention it anyway:
� Could not resolve 'package.json' from slamdata\output\SlamData.Config.Version\foreign.js
The culprit being: https://github.com/slamdata/slamdata/blob/41c5abb3dc3b31bfdb5d32e1626ae5d87c817ed2/src/SlamData/Config/Version.js
Is there even an acceptable way this could be done in ES6?
Is that code going to be run on Node or in the browsers?
In other words, do you want it to simply delegate to Node's require("package.json")
, or do you want it to actually put the package.json
file into the bundle?
It's for the browser - the app has its version in the UI / title bar, so to keep it in sync with release versions it's pulled in from there.
Okay, so I did a lot of digging into this.
First off, that require
is invalid in Node: try going into the src/SlamData/Config
folder, then run node
, then do require("package.json")
It seems you're using some features of Webpack in order to resolve it.
Therefore, I recommend changing it to require("../../../package.json")
However, if you want to keep it as require("package.json")
, you will need to use the rollup-plugin-alias
plugin.
In addition, you will need the rollup-plugin-json
plugin to load the JSON file.
Rollup is very barebones: it only handles ES6 modules, nothing else, so most features are provided by plugins.
Here is an example configuration using rollup-plugin-alias
and rollup-plugin-json
:
import path from "path";
import alias from "rollup-plugin-alias";
import json from "rollup-plugin-json";
import purs from "rollup-plugin-purs";
export default {
entry: "src/Main.purs",
dest: "bundle.js",
format: "iife",
sourceMap: true,
plugins: [
alias({
resolve: [""],
"package.json": path.join(__dirname, "package.json")
}),
json(),
purs()
]
};
The package.json
file will be included in the bundle, but it is tree-shaken and inlined, so it should only include the "version"
property in the bundle.