I am trying to get free code camp running locally offline and am having an issue. I followed the guide Contribution Guidelines | freeCodeCamp.org and everything works fine when connected to wifi but running pnpm develop without wifi gives an error
FetchError: request to https://cdn.freecodecamp.org/universal/trending/english.yaml failed, reason: getaddrinfo ENOTFOUND cdn.freecodecamp.org
I was under the impression that after downloading and running the command the first time, internet would not be required after that. Is internet always required for pnpm develop?
I often develop without internet access. All that is required is:
a) pnpm i to get all the node_modules
b) pnpm run develop to build the configs, download trending.json, and download the component library packages
c) OPTIONAL but recommended: Change the build:css script to remove the dlx command. That way, the component library does not spend an extra 20min trying to fetch stuff from the net.
Thanks for the clarification. I tried removing the dlx command from build:css but did not notice much of a difference, it will still fail to run without internet. Is there no way to cache the configs and the trending.json after the first initial running of pnpm develop?
The problem is in the client/tools/download-trending.ts file, the download function here is fetching the trending JSON each time and will throw an error if not found
I adjusted this function to use the existing trending JSON file if it exists and now I am able to run pnpm develop completely offline
const download = async (clientLocale: string) => {
const url = createCdnUrl(clientLocale)
const trendingLocation = path.resolve(
__dirname,
`../i18n/locales/${clientLocale}/trending.json`
)
const loadTrendingJSON = async () => {
try {
const res = await fetch(url)
const data = await res.text()
const trendingJSON = JSON.stringify(yaml.load(data))
return trendingJSON
} catch (error) {
const cachedTrendingJSON = readFileSync(trendingLocation, 'utf8')
if (!cachedTrendingJSON) {
throw new Error(
`
----------------------------------------------------
Error: The CDN is missing the trending YAML file.
----------------------------------------------------
Unable to fetch the ${clientLocale}
`
)
}
return cachedTrendingJSON
}
}
const trendingJSON = await loadTrendingJSON()
writeFileSync(trendingLocation, trendingJSON)
const trendingObject = JSON.parse(trendingJSON) as Record<string, string>
const validationError =
(trendingSchemaValidator(trendingObject).error as Error) || null
if (validationError) {
throw new Error(
`
----------------------------------------------------
Error: The trending JSON is invalid.
----------------------------------------------------
Unable to validate the ${clientLocale} trending JSON schema: ${validationError.message}
`
)
}
}