【问题标题】:TS2304: Cannot find name <class name>TS2304:找不到名称 <类名>
【发布时间】: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


    【解决方案1】:

    您应该在 nuxt 2.4 中使用 nuxt-ts。 请参阅发行说明https://github.com/nuxt/nuxt.js/releases/tag/v2.4.0

    【讨论】:

      猜你喜欢
      • 2019-04-21
      • 2022-01-20
      • 2017-08-11
      • 2017-08-23
      • 1970-01-01
      • 2017-11-03
      • 2019-12-24
      • 1970-01-01
      • 2017-11-26
      相关资源
      最近更新 更多