这个问题出现在我试图在我的 Sapper 项目上安装 Mongoose 后。
util.js:157
throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function', superCtor);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type function. Received undefined
at Object.inherits (util.js:157:11)
at Object.<anonymous> (<project path>\__sapper__\dev\server\server.js:140600:8)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'ERR_INVALID_ARG_TYPE'
}
> Server crashed
<project path>是我的项目路径
我有一个理论,这是由于将服务器代码捆绑/压缩成单个文件(__sapper__/dev/server.js
)导致的,但不确定如何解决。
如果有帮助的话,这是我的服务器rollup配置:
{
server: {
input: { server: config.server.input().server.replace(/\.js$/, '.ts') },
output: { ...config.server.output(), sourcemap },
plugins: [
replace({
'process.browser': false,
'process.env.NODE_ENV': JSON.stringify(mode),
'module.require': 'require',
}),
svelte({
generate: 'ssr',
dev,
preprocess,
}),
resolve({
dedupe: ['svelte'],
}),
commonjs({
sourceMap: !!sourcemap,
}),
typescript({
noEmitOnError: !dev,
sourceMap: !!sourcemap,
}),
json(),
],
external: [...Object.keys(pkg.dependencies).concat(
require('module').builtinModules || Object.keys(process.binding('natives')),
), 'saslprep'],
preserveEntrySignatures: 'strict'
},
}
配置大部分基于这个模板