【发布时间】:2019-02-01 08:20:26
【问题描述】:
我将我的 nuxt.js 更新为最新版本 (2.4.2)。当我更新时,当我执行 npm run dev 时它会返回 Cannot find name ,但在 nuxt.js 1 之前它已找到。我的代码是这样的:
资产/脚本/b.ts
export default class B {}
资产/脚本/a.ts
import B from "assets/scripts/b"
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "es2015"],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": ".",
"types": ["node"],
"typeRoots": [
"node_modules/@types",
"types/*"
]
},
"compileOnSave": true
}
模块:typescript.js
module.exports = function () {
// Add .ts & .tsx extension to Nuxt
this.nuxt.options.extensions.push('ts', 'tsx')
// Extend webpack build
this.extendBuild(config => {
// Add TypeScript
config.module.rules.push({
test: /\.tsx?$/,
loader: 'ts-loader',
options: { appendTsSuffixTo: [/\.vue$/] }
})
// Add .ts extension in webpack resolve
if (! config.resolve.extensions.includes('.ts')) {
config.resolve.extensions.push('.ts')
}
// Add .tsx extension in webpack resolve
if (! config.resolve.extensions.includes('.tsx')) {
config.resolve.extensions.push('.tsx')
}
})
}
【问题讨论】:
标签: typescript vuejs2 nuxt.js