NOTE: This worked until I changed type
to module
to fix a different problem.
I have this prebuild ts script for my Vue app:
// Adds the version as an environment variable
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { version } from './package.json';
const versionVariable = 'VITE_APP_VERSION = ';
const versionRegExp = new RegExp(`^${versionVariable}.*$`, 'gm');
let envContent = existsSync(".env") ? readFileSync(".env", 'utf-8') : '';
if (envContent.match(versionRegExp)) {
envContent = envContent.replace(versionRegExp, `${versionVariable}${version}`);
} else {
envContent += `\n${versionVariable}${version}`;
}
writeFileSync(".env", envContent);
However, I get this error:
Cannot find module './package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
However, I already have resolveJsonModule
set:
{
"files": [],
"compilerOptions": {
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
},
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
]
}
Here is my package.json:
{
"type": "module",
"scripts": {
...
"build": "run-p type-check build-only",
"prebuild": "tsc prebuild.ts && node prebuild.js && rm prebuild.js"
}
...
}