简体   繁体   English

语法错误:不能在 typescript 中的模块外使用导入语句

[英]SyntaxError: Cannot use import statement outside a module in typescript

I want to add this library to my nextjs with ts but I get the next error:我想用 ts将此库添加到我的 nextjs 中,但出现下一个错误:

Server Error

SyntaxError: Cannot use import statement outside a module
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
import React, { useState } from 'react';
import CalendarTemplate from 'availability-calendar-react';
import dynamic from 'next/dynamic'

const Page: React.FC = () => {
  const [availability, setAvailability] = useState([])
  const Calendar = CalendarTemplate({
    availability,
    setAvailability
  })
  return (
    <div>
      <Calendar />
    </div>
  );
};

export default Page;

For reference I am using this dashboard I am getting the error when i refresh the page作为参考,我正在使用此仪表板,刷新页面时出现错误

Remove the {} braces from your import.从您的导入中删除{}大括号。

import {CalendarTemplate} from 'availability-calendar-react';

should be应该

import CalendarTemplate from 'availability-calendar-react';

This package uses a default export.此 package 使用默认导出。

See https://blog.atomist.com/typescript-imports/ how imports work.请参阅https://blog.atomist.com/typescript-imports/导入的工作原理。

This probably does not fix all your issues but due to the lack of other files not provided it is hard to tell.这可能无法解决您的所有问题,但由于缺少未提供的其他文件,因此很难判断。 Cannot use import statement outside a module is an error occuring when using ES module syntax in non modules. Cannot use import statement outside a module是在非模块中使用 ES 模块语法时发生的错误。 Load your script as module and it should work.将您的脚本加载为模块,它应该可以工作。 See this for further instructions: https://bobbyhadz.com/blog/javascript-syntaxerror-cannot-use-import-statement-outside-module有关详细说明,请参阅此: https://bobbyhadz.com/blog/javascript-syntaxerror-cannot-use-import-statement-outside-module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;SyntaxError: 不能在模块外使用 import 语句&#39; - 'SyntaxError: Cannot use import statement outside a module' SyntaxError: 不能在模块外使用 import 语句是什么意思? - What does it mean SyntaxError: Cannot use import statement outside a module? Jest - SyntaxError: 无法在模块外使用 import 语句 - Jest - SyntaxError: Cannot use import statement outside a module 未捕获的 SyntaxError 无法在模块外使用 import 语句 - Uncaught SyntaxError Cannot use import statement outside a module SyntaxError:无法在模块 React JS Antd 之外使用 import 语句 - SyntaxError: Cannot use import statement outside a module React JS Antd 导入 React = &#39;SyntaxError: 不能在模块外使用导入语句&#39; - Importing React = 'SyntaxError: Cannot use import statement outside a module' React 16: SyntaxError: 不能在模块外使用 import 语句 - React 16: SyntaxError: Cannot use import statement outside a module SyntaxError: 不能在模块外使用 import 语句——React - SyntaxError: Cannot use import statement outside a module — React 如何修复“语法错误:无法在模块外使用导入语句” - How to fix “SyntaxError: Cannot use import statement outside a module” Typescript,反应,Electron:不能在模块外使用导入语句 - Typescript, React, Electron: Cannot use import statement outside a module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM