Skip to content

Named export not found. The request module is a CommonJS module #81

@maverick891

Description

@maverick891

I installed capacitor with sveltekit and was able to build my android app successfully. However, the build step (npm run build) fails when I try to use "send-intent"

I put the following code in my sveltekit application as instructed:

<script lang="ts">
  import "../app.postcss";
  import Navbar from "./navbar.svelte";

  import {SendIntent} from "send-intent";
  import { Filesystem } from '@capacitor/filesystem';

  SendIntent.checkSendIntentReceived().then((result: any) => {
      if (result) {
          console.log('SendIntent received');
          console.log(JSON.stringify(result));
      }
      if (result.url) {
          let resultUrl = decodeURIComponent(result.url);
          Filesystem.readFile({path: resultUrl})
          .then((content) => {
              console.log(content.data);
          })
          .catch((err) => console.error(err));
      }
  }).catch(err => console.error(err));
</script>

when I run

npm run build

I get the follwwing error:

file:///E:/Startup/Svelte/TSSKFE/.svelte-kit/output/server/entries/pages/_layout.svelte.js:6
import { SendIntent } from "send-intent";
         ^^^^^^^^^^
SyntaxError: Named export 'SendIntent' not found. The requested module 'send-intent' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'send-intent';
const { SendIntent } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)

node:internal/event_target:1037
  process.nextTick(() => { throw err; });
                           ^
Error: 500 /
To suppress or handle this error, implement `handleHttpError` in https://kit.svelte.dev/docs/configuration#prerender
    at file:///E:/Startup/Svelte/TSSKFE/node_modules/@sveltejs/kit/src/core/config/options.js:212:13
    at file:///E:/Startup/Svelte/TSSKFE/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:64:25
    at save (file:///E:/Startup/Svelte/TSSKFE/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:403:4)
    at visit (file:///E:/Startup/Svelte/TSSKFE/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:236:3)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:323:10)
    at [kOnMessage] (node:internal/worker:334:37)
    at MessagePort.<anonymous> (node:internal/worker:229:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:762:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v20.1.0

If I try the suggestion mentioned in the error above, the error changes to:

error during build:
RollupError: "default" is not exported by "node_modules/send-intent/dist/esm/index.js", imported by "src/routes/+layout.svelte".
    at error (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
    at Module.error (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:13572:16)
    at Module.traceVariable (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:13997:29)
    at ModuleScope.findVariable (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:12515:39)
    at FunctionScope.findVariable (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:7073:38)
    at ChildScope.findVariable (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:7073:38)
    at Identifier.bind (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:8235:40)
    at VariableDeclarator.bind (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:5841:23)
    at VariableDeclaration.bind (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:5837:28)
    at BlockStatement.bind (file:///E:/Startup/Svelte/TSSKFE/node_modules/rollup/dist/es/shared/node-entry.js:5837:28)

I tried googling and trying every solution offered on stackoverflow and on other websites but nothing worked for me. I am aware this might not be an issue bug with module but my mistake. Please help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions