1

Hello I am trying to use yoastseo plugin in NextJS, but when i import it i`m getting some strange errors. Bellow is my code

import { Researcher, Paper } from 'yoastseo';

const paper = new Paper('Text to analyze', {
  keyword: 'analyze',
});
const researcher = new Researcher(paper);

below is what i get in the terminal.

import { AnalysisWebWorker, AnalysisWorkerWrapper, createWorker } from "./src/worker";        
^^^^^^

SyntaxError: Cannot use import statement outside a module

And that's what I get in the browser window.

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.
Source
external%20%22yoastseo%22 (1:0) @ Object.yoastseo

> 1 | module.exports = require("yoastseo");

I used the plugin it with create-react-app without any issues. I guess its related to how NextJS is loading the web worker.

Pecata
  • 683
  • 8
  • 13
  • Does this help answer your question [Import ES module in Next.js ERR_REQUIRE_ESM](https://stackoverflow.com/a/65978156/1870780). Different library, but same solution. – juliomalves Apr 07 '21 at 22:24
  • That solves the problem in nextjs.config.js but as soon s i import the module in my component the whole NextJS crashes. <--- Last few GCs ---> [5988:000002BD82DA2850] 73587 ms: Scavenge (reduce) 4090.9 (4099.7) -> 4090.3 (4100.7) MB, 8.5 / 0.0 ms (average mu = 0.113, current mu = 0.040) allocation failure [5988:000002BD82DA2850] 73596 ms: Scavenge (reduce) 4091.1 (4099.7) -> 4090.7 (4100.7) MB, 7.5 / 0.0 ms (average mu = 0.113, current mu = 0.040) allocation failure [5988:000002BD82DA2850] 73606 ms: Scavenge (reduce) 4091.2 (4102.7) -> 4091.3 (4103.5) MB, 9.8 / 0.0 ms (a... – Pecata Apr 08 '21 at 09:28
  • I think https://stackoverflow.com/questions/62488898/node-js-syntaxerror-cannot-use-import-statement-outside-a-module will solve your problem. – Aflah vp Feb 08 '22 at 07:54

0 Answers0