Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Cannot use import statement outside a module #10

Open
sarimabbas opened this issue Mar 31, 2021 · 2 comments
Open

SyntaxError: Cannot use import statement outside a module #10

sarimabbas opened this issue Mar 31, 2021 · 2 comments

Comments

@sarimabbas
Copy link

sarimabbas commented Mar 31, 2021

Thanks for making this lib! It works beautifully in create-react-app but not in next. Would you have any suggestions for how to rectify this?

Thank you so much!

import Pattern from "url-knife";
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.
Source
external%20%22url-knife%22 (1:0) @ eval

> 1 | module.exports = require("url-knife");
@patternknife
Copy link
Owner

Hi, I guess it was caused by a ssr option. What about this?

import dynamic from 'next/dynamic';
// import Pattern from "url-knife";
const Pattern = dynamic(() => import('url-knife'), { ssr: false });

@lucasnantonio
Copy link

I'm having this same issue and the above suggestion didn't work for me. I get:

Could not find a declaration file for module 'url-knife'. '.../node_modules/url-knife/src/entry.js' implicitly has an 'any' type.

 Try npm i --save-dev @types/url-knife if it exists or add a new declaration (.d.ts) file containing `declare module 'url-knife';
Property 'TextArea' does not exist on type 'ComponentType<{}>'.
 Property 'TextArea' does not exist on type 'ComponentClass<{}, any>'.
    at getTopUrls (webpack-internal:///./utils/getUrls.tsx:65:40)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  79 |   );
  80 | 
> 81 |   let urls = Pattern.TextArea.extractAllFuzzyUrls(myText);
     |                                     ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants