[英]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.