I have been encountering an issue with my appsettings.json file. Despite it being validated by jsonlint.com, and having the tsconfig resolveJsonModule option set to true, I am facing difficulties while importing @rollup/plugin-json. I have experimented with different positions for calling the plugin within the chain of plugins, but unfortunately, I keep receiving the following error:
(!) Plugin json: Could not parse JSON file
appsettings.json
[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
appsettings.json (2:10)
It seems like the plugin is triggered, yet it fails to parse the supposedly valid file. The configuration in my Rollup setup appears as follows:
//imports...
console.log(`Node env is ${process.env.NODE_ENV}`);
let isDevEnv = process.env.NODE_ENV === 'development';
let useMsw = process.env.USE_MSW;
const extensions = ['.cjs', '.js', '.jsx', '.json', '.ts', '.tsx', '.css', '.png'];
const intro = `global = window; window.NODE_ENV = process.env.NODE_ENV; ${useMsw ? 'window.USE_MSW = true;' : ''}`;
export default {
input: [
'src/index.tsx'
],
output: {
intro: intro,
file: './dist/bundle.js',
format: 'es',
sourcemap: isDevEnv,
inlineDynamicImports: true,
},
plugins: [
//plugins list...
json(),
]
};
My tsconfig file is configured as below:
{
"compilerOptions": {
//options...
"resolveJsonModule": true
},
"include": [
//included paths...
],
"exclude": ["node_modules"]
}
The structure of my actual json file is as shown:
{
"HUB_URL": "theHubUrl",
"AUTH_ENDPOINT": "https://localhost:44330/API/Dispatch/Authentication/v1.0/authenticate",
//more key-value pairs...
}
Despite several attempts and adjustments, the Rollup output consistently displays the same error message regarding the inability to parse the JSON file. Any insights or suggestions would be greatly appreciated. Thank you.