Javascript TS1128';预期的声明或声明';赢得';即使代码看起来很好,也不要走开
这与中提出的问题完全相同,但该问题从未得到答案 我正在写一个NodeJS/JavaScript/Keystone项目。我的WebStorm IDE表明我的代码中有错误(这在文件的末尾): 我已经尝试过一次连续注释/删除一段代码,直到什么都没有了。只有删除所有代码,错误才会消失 我不知道错误是从哪里来的。所有括号/括号似乎都匹配。我也不知道这是一个TypeScript错误,一个ESLint错误还是其他什么 代码可以编译,但项目不再正常运行,我想知道指示错误的事实是否指向导致项目失败的一些潜在问题 此文件的代码为:Javascript TS1128';预期的声明或声明';赢得';即使代码看起来很好,也不要走开,javascript,node.js,typescript,eslint,Javascript,Node.js,Typescript,Eslint,这与中提出的问题完全相同,但该问题从未得到答案 我正在写一个NodeJS/JavaScript/Keystone项目。我的WebStorm IDE表明我的代码中有错误(这在文件的末尾): 我已经尝试过一次连续注释/删除一段代码,直到什么都没有了。只有删除所有代码,错误才会消失 我不知道错误是从哪里来的。所有括号/括号似乎都匹配。我也不知道这是一个TypeScript错误,一个ESLint错误还是其他什么 代码可以编译,但项目不再正常运行,我想知道指示错误的事实是否指向导致项目失败的一些潜在问题
import { Keystone } from '@keystonejs/keystone';
import { GraphQLApp } from '@keystonejs/app-graphql';
import { AdminUIApp } from '@keystonejs/app-admin-ui';
import { StaticApp } from '@keystonejs/app-static';
import { LocalFileAdapter } from '@keystonejs/file-adapters';
import { IframelyOEmbedAdapter } from '@keystonejs/oembed-adapters';
import { MongooseAdapter } from '@keystonejs/adapter-mongoose';
import { KnexAdapter } from '@keystonejs/adapter-knex';
import { PasswordAuthStrategy } from '@keystonejs/auth-password';
import lists from './lists';
import checkArticlePublishDates from './jobs/checkArticlePublishDates';
import log from './util/log';
import seedDb from './util/seedDb';
require('dotenv').config();
let authStrategy;
const PROJECT_NAME = process.env.PROJECT_NAME;
const iframelyAdapter = new IframelyOEmbedAdapter({
apiKey: process.env.IFRAMELY_KEY
});
const staticPath = 'public';
const staticRoute = '';
const imageFileAdapter = new LocalFileAdapter({
src: `${staticPath}/images`,
path: `${staticRoute}/images`
});
const keystone = new Keystone({
name: PROJECT_NAME,
adapter: new MongooseAdapter()
});
const createAuth = () => {
authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: 'User',
config: {
identityField: 'username', // default: 'email'
secretField: 'password' // default: 'password'
}
});
};
const createLists = () => lists(keystone, { imageFileAdapter, iframelyAdapter });
const setupCronJobs = async () => {
const checkPub = await checkArticlePublishDates(keystone);
};
const boot = async () => {
createLists();
createAuth();
await keystone.prepare({
cors: { origin: true, credentials: true }
});
await setupCronJobs();
};
boot();
export default {
keystone,
apps: [
new GraphQLApp(),
new AdminUIApp({
adminPath: '/admin',
hooks: require.resolve('./admin/'),
authStrategy,
enableDefaultRoute: true
}),
new StaticApp({
path: '/',
src: 'public',
fallback: 'index.html'
})
]
};
我的.eslintrc
文件是
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
},
"extends": [
"eslint:recommended",
"prettier",
"plugin:react/recommended",
],
"plugins": [
"prettier",
"react",
"react-hooks"
],
"env": {
"es6": true,
"node": true,
"mocha": true,
"browser": true
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": 1,
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/no-unescaped-entities": "warn",
"react/no-find-dom-node": 0,
"comma-dangle": ["error", "never"],
"global-require": 0
}
}
{
"compilerOptions": {
"target": "ES6",
"lib": [
"esnext",
"dom"
],
"skipLibCheck": true,
"outDir": "tsout",
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"sourceMap": true,
"alwaysStrict": true,
"jsx": "react"
},
"exclude": [
"node_modules"
]
}
我的tsconfig.json
文件是
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
},
"extends": [
"eslint:recommended",
"prettier",
"plugin:react/recommended",
],
"plugins": [
"prettier",
"react",
"react-hooks"
],
"env": {
"es6": true,
"node": true,
"mocha": true,
"browser": true
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": 1,
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/no-unescaped-entities": "warn",
"react/no-find-dom-node": 0,
"comma-dangle": ["error", "never"],
"global-require": 0
}
}
{
"compilerOptions": {
"target": "ES6",
"lib": [
"esnext",
"dom"
],
"skipLibCheck": true,
"outDir": "tsout",
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"sourceMap": true,
"alwaysStrict": true,
"jsx": "react"
},
"exclude": [
"node_modules"
]
}
正如@Cerulean所说,对我来说,文件本身似乎存在问题。我有与上面描述的完全相同的问题,并且也在使用WebStorm
我创建了一个新文件,将代码作为纯文本粘贴到其中,并保存了该文件。没有ESLint问题。因此,我删除了旧文件,并将这个新文件重命名为旧文件的名称。工作正常,没有错误。我将此文件的内容复制到一个新文件中,解决了问题。但我不明白发生了什么。在执行此操作之前,我已清除WebStorm缓存,但没有任何帮助。这是Typescript报告的错误,因为消息以“TS1128:…”开头。不过代码看起来不错。