CapacitorGoogleAuth icon indicating copy to clipboard operation
CapacitorGoogleAuth copied to clipboard

Cannot use import statement outside a module

Open jamesrgrace opened this issue 2 years ago • 3 comments

Trying to use the library in a project that uses NextJS & React.

The web version of the app runs on NodeJS in a Google Cloud env. I'm trying to use CapacitorJS to implement iOS and Android versions of the app.

Here is my babel.config.json :

{
    "presets": ["next/babel"],
    "plugins": [["styled-components", { "ssr": true }]]
}

I can't run "next build" successfully. I get this :

import { registerPlugin } from '@capacitor/core';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.845 (/Users/jamesgrace/handsdown-web/.next/server/pages/login.js:345:18)
    at __webpack_require__ (/Users/jamesgrace/handsdown-web/.next/server/webpack-runtime.js:25:42) {
  type: 'SyntaxError'
}

jamesrgrace avatar Sep 15 '22 02:09 jamesrgrace

I was able to get things working with this library but it would be nice if this library was released transpiled : https://github.com/martpie/next-transpile-modules

jamesrgrace avatar Sep 15 '22 15:09 jamesrgrace

What was the solution to this issue?

Jdowsett21 avatar Nov 20 '22 00:11 Jdowsett21

@Jdowsett21 in your next.js config

// yarn add next-transpile-modules
const withTM = require('next-transpile-modules')([
      '@codetrix-studio/capacitor-google-auth',
]);
return withTM(nextConfig);

fletcherist avatar Dec 20 '22 21:12 fletcherist