在Webpack编译期间收到错误:
ERROR in d:\Work\.Projects\projectweb\VueApp\app.ts
./VueApp/app.ts
[tsl] ERROR in d:\Work\.Projects\projectweb\VueApp\app.ts(2,32)
TS2551: Property 'setPrototypeOf' does not exist on type 'ObjectConstructor'. Did you mean 'getPrototypeOf'?
(以及更多)
我的app.ts
很简单:
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator'
import VueBase from './vueBase';
@Component({})
export default class App extends VueBase {
}
没有setPrototypeOf
,问题显然来自导入。为什么错误没有显示正确的位置,而是显示app.ts
中有错误?
tsconfig
:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true
}
}
webpack配置:
//@ts-check
'use strict';
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var WebpackNotifierPlugin = require('webpack-notifier');
/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context ? -> https://webpack.js.org/configuration/node/
entry: './VueApp/main.ts', // the entry point of this extension, ? -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), ? -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, ? -> https://webpack.js.org/configuration/externals/
},
resolve: {
// support reading TypeScript and JavaScript files, ? -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.scss$/,
use: [
'vue-style-loader',
'style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/],
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader'
]
}
// other vue-loader options go here
}
},
]
},
plugins: [
new VueLoaderPlugin(),
new WebpackNotifierPlugin({
alwaysNotify: true
}),
]
};
module.exports = config;
我还想知道为什么首先出现错误。
我尝试过3.6.3
和2.9.2
版打字稿