patternhelloworld / url-knife

Extract and decompose URLs (including emails, which are conceptually a part of URLs) with robust patterns.
MIT License
340 stars 15 forks source link

SyntaxError: Cannot use import statement outside a module #10

Open sarimabbas opened 3 years ago

sarimabbas commented 3 years ago

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");
patternhelloworld commented 3 years ago

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 commented 1 year ago

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);
     |                                     ^
patternhelloworld commented 3 months ago

"I have upgraded the version in 'package.json'. I recommend using the latest version.