Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module #10

Closed
mehdiraized opened this issue May 31, 2020 · 8 comments
Closed

Cannot find module #10

mehdiraized opened this issue May 31, 2020 · 8 comments
Labels
duplicate This issue or pull request already exists

Comments

@mehdiraized
Copy link

Error: Cannot find module '/front/node_modules/@beyonk/svelte-mapbox/index.mjs'. Please verify that the package.json has a valid "main" entry

at tryPackage (internal/modules/cjs/loader.js:322:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:683:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:953:27)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/front/__sapper__/dev/server/server.js:24:20)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/front/node_modules/@beyonk/svelte-mapbox/package.json',
  requestPath: '@beyonk/svelte-mapbox'
@antony
Copy link
Member

antony commented May 31, 2020

@mehdiraized without knowing anything about how you are trying to bundle this into your application, I can't help you.

Please let me know if you are using Rollup or Webpack or Parcel, what stack you are using, etc

@mehdiraized
Copy link
Author

Rollup

@mehdiraized without knowing anything about how you are trying to bundle this into your application, I can't help you.

Please let me know if you are using Rollup or Webpack or Parcel, what stack you are using, etc

@antony
Copy link
Member

antony commented May 31, 2020

@mehdiraized please post your rollup config, details about how you installed the module, details about how you're importing the module into your project etc

@mehdiraized
Copy link
Author

config default sapper

import svelte from "rollup-plugin-svelte";
import alias from "@rollup/plugin-alias";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import replace from "@rollup/plugin-replace";
import sveltePreprocess from "svelte-preprocess";
import babel from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
import config from "sapper/config/rollup.js";
import pkg from "./package.json";

const mode = process.env.NODE_ENV;
const dev = mode === "development";
const legacy = !!process.env.SAPPER_LEGACY_BUILD;

const onwarn = (warning, onwarn) =>
  (warning.code === "CIRCULAR_DEPENDENCY" &&
    /[/\\]@sapper[/\\]/.test(warning.message)) ||
  onwarn(warning);
const dedupe = ["svelte", "svelte/internal"];

const preprocess = sveltePreprocess({
  scss: {
    includePaths: ["src"],
  },
  postcss: {
    plugins: [require("autoprefixer")],
  },
});

export default {
  client: {
    input: config.client.input(),
    output: config.client.output(),
    cache: true,
    plugins: [
      replace({
        "process.browser": true,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      svelte({
        dev,
        hydratable: true,
        emitCss: true,
        preprocess,
      }),
      alias({
        entries: [
          {
            find: `@sapper`,
            replacement: `${__dirname}/src/node_modules/@sapper`,
          },
        ],
      }),
      resolve({
        browser: true,
        dedupe,
      }),
      commonjs(!dev && { sourceMap: false }),

      legacy &&
        babel({
          extensions: [".js", ".mjs", ".html", ".svelte"],
          babelHelpers: "runtime",
          exclude: ["node_modules/@babel/**"],
          presets: [
            [
              "@babel/preset-env",
              {
                targets: "> 0.25%, not dead",
              },
            ],
          ],
          plugins: [
            "@babel/plugin-syntax-dynamic-import",
            [
              "@babel/plugin-transform-runtime",
              {
                useESModules: true,
              },
            ],
          ],
        }),

      !dev &&
        terser({
          module: true,
        }),
    ],

    preserveEntrySignatures: false,
    onwarn,
  },

  server: {
    input: config.server.input(),
    output: config.server.output(),
    cache: true,
    plugins: [
      replace({
        "process.browser": false,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      svelte({
        generate: "ssr",
        hydratable: true,
        dev,
        preprocess,
      }),
      alias({
        entries: [
          {
            find: `@sapper`,
            replacement: `${__dirname}/src/node_modules/@sapper`,
          },
        ],
      }),
      resolve({
        dedupe,
      }),
      commonjs(!dev && { sourceMap: false }),
    ],
    external: Object.keys(pkg.dependencies).concat(
      require("module").builtinModules ||
        Object.keys(process.binding("natives"))
    ),

    onwarn,
  },

  serviceworker: {
    input: config.serviceworker.input(),
    output: config.serviceworker.output(),
    cache: true,
    plugins: [
      resolve(),
      replace({
        "process.browser": true,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      alias({
        entries: [
          {
            find: `@sapper`,
            replacement: `${__dirname}/src/node_modules/@sapper`,
          },
        ],
      }),
      commonjs(!dev && { sourceMap: false }),
      !dev && terser(),
    ],

    onwarn,
  },
};

@antony
Copy link
Member

antony commented May 31, 2020

You need to ensure you're installing as a development dependency:

npm install --save-dev @beyonk/svelte-mapbox

@antony antony added duplicate This issue or pull request already exists and removed pending clarification labels May 31, 2020
@antony
Copy link
Member

antony commented May 31, 2020

Duplicate of #1 and #3

@antony antony closed this as completed May 31, 2020
@mehdiraized
Copy link
Author

plz add to readme file

Duplicate of #1 and #3

@antony
Copy link
Member

antony commented May 31, 2020

Done - b9f623c

It's important that you understand that this applies to any library you use with Svelte/Sapper. You do not need runtime dependencies except in very specific circumstances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants