首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TS8006:“导入类型”声明只能在TypeScript文件中使用

TS8006:“导入类型”声明只能在TypeScript文件中使用
EN

Stack Overflow用户
提问于 2022-09-06 09:20:00
回答 1查看 218关注 0票数 0

构建React和rollup会遇到以下错误:

rollup.config.js

代码语言:javascript
复制
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import ts from "rollup-plugin-ts";
import jsx from 'acorn-jsx';
import tsConfig from './tsconfig.json';
const config = [
    {
        input: "index.ts",
        output: [{ file: "build/index.js", sourcemap: true }],
        acornInjectPlugins: [jsx()],
        plugins: [
            typescript(
                {
                    sourceMap: tsConfig.compilerOptions.sourceMap
                }
            ),
            json()
        ]
    },
    {
        input: "index.ts",
        output: [{ file: "build/index.d.ts", "format": "es" }],
        acornInjectPlugins: [jsx()],
        plugins: [
            ts(
                {
                    compilerOptions: {
                        baseUrl: tsConfig.compilerOptions.baseUrl
                    }
                }
            ),
            json()
        ]
    },
]

export default config;
代码语言:javascript
复制
2: import clsx from "clsx";
3: import { sortBy } from "lodash";
4: import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
            ^
5: import { Direction } from "react-beautiful-dnd/src/types";
6: import makeStyles from "@mui/styles/makeStyles";
...and 2 other occurrences
[!] (plugin Typescript) TS8006: 'import type' declarations can only be used in TypeScript files.
node_modules/react-beautiful-dnd/src/types.js (2:1)

2 import type { BoxModel, Rect, Position } from 'css-box-model';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EN

回答 1

Stack Overflow用户

发布于 2022-10-13 16:39:08

在VSCode中:

  1. 确保安装了扩展流语言支持.

代码语言:javascript
复制
- Go to extensions
- Type: Flow Language Support
- Install the Flow Language Support extension

  1. 转到扩展并禁用TypeScript和JavaScript Language

代码语言:javascript
复制
- Go to extensions
- Type: @builtin TypeScript and JavaScript Language Features
- Disable the extension
- Click on Reload Required
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73619580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档