打字稿:意外令牌`接口' w/ react js
- 在我在本地主机上运行dev之后,我会发现错误: x意外令牌
接口
。期待此,导入,异步,函数,[对于数组字面,{对于object triletal, @ for Decorator,function,class,class,null,null,true,false,number,bigint,bigint,string,string,string, | regexp,`对于模板字面的,(或标识符
这是代码的摘要:
interface SidebarProps {
initialSelectedIcon: string
}
function Sidebar({ initialSelectedIcon }: SidebarProps) {
const [selected, setSelected] = useState<String>(initialSelectedIcon)
const { currentAccount, currentUser } = useContext(TwitterContext)
const router = useRouter()
终端中没有问题
我没有问题,我将一堆JS文件转换为tsx
这是我的tsconfig.json
{ “ compileroptions”:{ “目标”:“ ES6”, “ lib”:[“ dom”,“ dom.iterable”,“ esnext”], “允许J”:是的, “ Skiplibcheck”:是的, “严格”:是的, “ forceconsistentcasinginfilenames”:是的, “ noemit”:是的, “ eSmoduleInterop”:true, “模块”:“ commonjs”, “ Moduleresolution”:“ Node”, “ resolvejsonmodule”:是的, “孤立模块”:是的, “ JSX”:“ Preserve”, “增量”:正确 },, “ inclage”:[“ next-env.d.ts”,“ **/*。ts”,“ **/*。tsx”, “页面/组件/2_sidebar.tsx”], “排除”:[“ node_modules”] }
下面是我的软件包
“脚本”:{ “构建”:“ rimraf ./build&amp;&amp; tsc”, “ dev”:“ nodemon”, “ start”:“ npm运行构建&amp;&amp; node build/index.tsx” },, “关键字”:[ “理智” ],, “依赖关系”:{ “@Sanity/Base”:“^2.29.5”, “@Sanity/Core”:“^2.29.5”, “@sanity/default-layout”:“^2.29.5”, “@sanity/default-login”:“^2.29.5”, “@Sanity/Desk-Tool”:“^2.29.5”, “@sanity/eslint-config-studio”:“^2.0.0”, “@Sanity/Vision”:“^2.29.5”, “ eslint”:“^8.6.0”, “ prop-types”:“^15.7”, “反应”:“^17.0”, “ react-dom”:“^17.0”, “样式组件”:“^5.2.0” },, “ devDectiencies”:{ “@type/node”:“^17.0.21”, “ nodemon”:“^2.0.15”, “ rimraf”:“^3.0.0”, “ TS节点”:“^10.4.0”, “打字稿”:“^4.6.2” } }
- 。
- After I npm run dev on local host I get the error:
x Unexpected tokeninterface
. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string,
| regexp, ` for template literal, (, or an identifier
This is a snippet of the code:
interface SidebarProps {
initialSelectedIcon: string
}
function Sidebar({ initialSelectedIcon }: SidebarProps) {
const [selected, setSelected] = useState<String>(initialSelectedIcon)
const { currentAccount, currentUser } = useContext(TwitterContext)
const router = useRouter()
There are no problems in the Terminal
I converted a bunch of js files to tsx
Here is my tsconfig.json
{ "compilerOptions": { "target": "es6", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, "module": "commonjs", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "pages/components/2_Sidebar.tsx"], "exclude": ["node_modules"] }
Below is my Package.json
"scripts": { "build": "rimraf ./build && tsc", "dev": "nodemon", "start": "npm run build && node build/index.tsx" }, "keywords": [ "sanity" ], "dependencies": { "@sanity/base": "^2.29.5", "@sanity/core": "^2.29.5", "@sanity/default-layout": "^2.29.5", "@sanity/default-login": "^2.29.5", "@sanity/desk-tool": "^2.29.5", "@sanity/eslint-config-studio": "^2.0.0", "@sanity/vision": "^2.29.5", "eslint": "^8.6.0", "prop-types": "^15.7", "react": "^17.0", "react-dom": "^17.0", "styled-components": "^5.2.0" }, "devDependencies": { "@types/node": "^17.0.21", "nodemon": "^2.0.15", "rimraf": "^3.0.0", "ts-node": "^10.4.0", "typescript": "^4.6.2" } }
I think there might be a problem with the tsconfig.json or package.json
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论