0

I want to add this library to my nextjs with ts but I get the next error :

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

1
  • @OMiShah same thing Commented Aug 25, 2022 at 18:44

1 Answer 1

2

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.

See https://blog.atomist.com/typescript-imports/ how imports work.

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. 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

Sign up to request clarification or add additional context in comments.

4 Comments

Same thing after I remove
And I use the exactly same dashboard as I linked in the description, just edit one template files (like integrations.tsx) with my code and you have the exact code i have
So in the end I switched to a full js framework, but ty
To the first comment: That's what I said with does not fix all your issues ;). The error is still there because of server code is using commonjs but tries to use import statement like in es modules. Even this is in nextjs, it's still the same problem in your react app: github.com/vercel/next.js/issues/9890

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.