I am using prop-types npm package with sapper and It working fine but when I migrate to sveltekit it gives error.
Command: npm run preview
Uses eg:
import * as PropTypes from "prop-types";
const {checkPropTypes, number} = PropTypes;
const propTypes = {
threshold: number,
};
checkPropTypes(propTypes, $$props, "prop", "Observer");
Error:
checkPropTypes is not a function
Putting the function inside
onMountseems to work:However, from my testing,
npm run devworks fine without changes, so it's strange that withnpm run previewit breaks. For some reason, bothcheckPropTypesandnumberare undefined when usingpreview. What's weirder is that the module object looks like this:So the function is there, it's just undefined. Again, it works correctly when using
build. And there's a lot more weird behaviour if you experiment more, so maybe it's just a SvelteKit issue.Anyways, you should simply use
onMountfor now to solve the issue.