0

I'm trying to implement i18n-perser with Next Js. According to the i18n-perser documentation I need to create a gulpfile.js on the root directory. My gulpfile.js is something like this.

import gulp from 'gulp';
import { gulp as i18nextParser } from 'i18next-parser';

export async function i18next() {
  return gulp
    .src('./**')
    .pipe(
      new i18nextParser({
        locales: ['en', 'nl'],
        output: './i18n/locales/$LOCALE/$NAMESPACE.json',
      })
    )
    .pipe(gulp.dest('./'));
}

It's gives me SyntaxError: Cannot use import statement outside a module. I tried some solution like the dynamic import. But it's not working for me in this case. It's giving me the same SyntaxError.

import dynamic from 'next/dynamic';
const gulp = dynamic(() => import('gulp'), { ssr: false });
const { gulp: i18nextParser } = dynamic(() => import('i18next-parser"'), { ssr: false });

I triend the dynamic import but it's also not working in my case. It's working perfectly in React but not working with NextJs. Basiclly if I run npm run gulp it will create parer file for me.

1 Answers1

0

Probably your project is set to use the CommonJS module system by default.

In that case, you could rename your gulpfile.js to gulpfile.mjs to keep using the import syntax.

GOTO 0
  • 42,323
  • 22
  • 125
  • 158
  • Its working after renaming the gulpfile.js to gulpfile.mjs. But it's giving me this error now. FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory – Sabbir Zzaman Dec 29 '22 at 11:03
  • @SabbirZzaman You should ask a new question for that. – GOTO 0 Dec 29 '22 at 12:41