Giter Club home page Giter Club logo

Comments (18)

yannbf avatar yannbf commented on June 12, 2024 4

Hey everyone! If you're using MSW 2.0.0, we just released a new beta version that should have fixed this issue: [email protected].

Would you please try it out and let us know? Thank you!
cc @satoshi-izawa @marksulls tagging you since I know you're using msw 2!

from msw-storybook-addon.

mribichich avatar mribichich commented on June 12, 2024 3

for those using vite, I was able to fix the not found ./native module by adding this to vite.config

  resolve: {
    alias: {
      'msw/native': require.resolve(path.resolve(__dirname, './node_modules/msw/lib/native/index.mjs')),
    },
  },

from msw-storybook-addon.

magus avatar magus commented on June 12, 2024 2

The types aren't correct for the 2.0.0-beta1 but everything else works otherwise!

from msw-storybook-addon.

satoshi-izawa avatar satoshi-izawa commented on June 12, 2024 1

I faced the same problem
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] No known conditions for "./native" specifier in "msw" package

msw-storybook-addon: 2.0.0-beta.0
msw: 2.0.13
vite: 5.0.11

from msw-storybook-addon.

belandrio avatar belandrio commented on June 12, 2024

I am facing the same issue

from msw-storybook-addon.

YouHusam avatar YouHusam commented on June 12, 2024

I am having the same issue, are there any workarounds?

from msw-storybook-addon.

jetzhliu avatar jetzhliu commented on June 12, 2024

npm i --save-dev msw@^1
ref: https://github.com/mswjs/msw-storybook-addon/blob/main/packages/msw-addon/package.json#L45

from msw-storybook-addon.

marksulls avatar marksulls commented on June 12, 2024

Similar to the Vite specific fix above, this Webpack configuration is working for me (Angular / Storybook / Nx workspace):

in .storybook/main.ts:

import { StorybookConfig } from "@storybook/angular";
import * as path from "path";

const config: StorybookConfig = {
  stories: ['../**/*.stories.@(js|jsx|ts|tsx|mdx)'],
  addons: [
    '@storybook/addon-interactions',
    '@storybook/addon-docs',
    '@storybook/addon-essentials',
  ],
  framework: {
    name: '@storybook/angular',
    options: {},
  },
  staticDirs: ['../src/lib/msw'],
  // webpack workaround see https://github.com/mswjs/msw-storybook-addon/issues/131#issuecomment-1887930180
  webpackFinal: async (config) => {
    if (config.resolve) {
      config.resolve.alias = {
        ...config.resolve.alias,
        'msw/native': require.resolve(
          path.resolve(__dirname, '../../../node_modules/msw/lib/native/index.mjs')
        )
      };
    }
    return config;
  }
};
"msw": "2.1.3",
"msw-storybook-addon": "2.0.0-beta.0",

from msw-storybook-addon.

henrybravos avatar henrybravos commented on June 12, 2024

worked for me:
//vite.config.ts

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { createRequire } from "node:module";
import path from "path";
const require = createRequire(import.meta.url);

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "msw/native": require.resolve(
        path.resolve(__dirname, "./node_modules/msw/lib/native/index.mjs")
      ),
    },
  },
});

from msw-storybook-addon.

bmulholland avatar bmulholland commented on June 12, 2024

For those who try it out, be very careful with your version specification in package.json. There's a "next" version of 2.0.0, 2.0.0-next.1, that is 9 months old -- but e.g. a version pin of >= 2.0.0-beta.1 will select that one. I suggest double checking your lockfile to see exactly what version you end up with.

from msw-storybook-addon.

bmulholland avatar bmulholland commented on June 12, 2024

Confirmed that the beta solves this issue for me πŸŽ‰

from msw-storybook-addon.

chapmanio avatar chapmanio commented on June 12, 2024

I've followed the vite-specific instructions here but I'm now getting this error:

[ERROR] No known conditions for "./node" specifier in "msw" package [plugin vite:dep-pre-bundle]

Is anyone having anything similar?

viteFinal: (config) => {
    config.resolve = {
      ...config.resolve,
      alias: {
        ...config.resolve?.alias,
        ["msw/native"]: require.resolve("../node_modules/msw/lib/native/index.mjs"),
      },
    };

    return mergeConfig(config, {
      plugins: [tsconfigPaths()],
    });
  },
    "msw": "^2.1.6",
    "msw-storybook-addon": "^2.0.0-beta.1",

from msw-storybook-addon.

aronchick avatar aronchick commented on June 12, 2024

@chapmanio i solved that because you're using "msw/node" in something that is client code only. You may need to swap to "msw/browser" (but this will prevent you from using server libraries like fs or path).

from msw-storybook-addon.

chapmanio avatar chapmanio commented on June 12, 2024

@chapmanio i solved that because you're using "msw/node" in something that is client code only. You may need to swap to "msw/browser" (but this will prevent you from using server libraries like fs or path).

Do you have a code example of how to do that? I'm not importing MSW in my code (I assume that is being done by msw-storybook-addon) so it's not clear how to change this.

from msw-storybook-addon.

glodynator avatar glodynator commented on June 12, 2024

I've followed the vite-specific instructions here but I'm now getting this error:

[ERROR] No known conditions for "./node" specifier in "msw" package [plugin vite:dep-pre-bundle]

Is anyone having anything similar?

viteFinal: (config) => {
    config.resolve = {
      ...config.resolve,
      alias: {
        ...config.resolve?.alias,
        ["msw/native"]: require.resolve("../node_modules/msw/lib/native/index.mjs"),
      },
    };

    return mergeConfig(config, {
      plugins: [tsconfigPaths()],
    });
  },
    "msw": "^2.1.6",
    "msw-storybook-addon": "^2.0.0-beta.1",

I'm having the same issue.

from msw-storybook-addon.

acc-nicholas avatar acc-nicholas commented on June 12, 2024

I'm having a similar issue: [vite] Internal server error: No known conditions for "./node" specifier in "msw" package

This works:

import { handlers } from "../mocks/handlers";

// Initialize MSW
initialize(
  {
    onUnhandledRequest: "warn",
  },
  [...handlers],
);

This does not work when importing from another lib in my monorepo.

import { handlers } from "@otherlib/mocks";

// Initialize MSW
initialize(
  {
    onUnhandledRequest: "warn",
  },
  [...handlers],
);

I have proper vite/typescript aliases/paths set up for this mocks lib btw.

"msw": "^2.2.1",
"msw-storybook-addon": "^2.0.0-beta.1",

from msw-storybook-addon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.