rollup / rollup-plugin-node-resolve

This module has moved and is now available at @rollup/plugin-node-resolve / https://github.com/rollup/plugins/blob/master/packages/node-resolve
MIT License
469 stars 96 forks source link

Resolve errors/warnings with modules #184

Closed ravecat closed 5 years ago

ravecat commented 6 years ago

In during assembly get errors/warnings

(!) Unresolved dependencies https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency stream (imported by node_modules/styled-components/dist/styled-components.esm.js) events (imported by commonjs-external:events, node_modules/@storybook/core/dist/client/preview/story_store.js) (!) The 'typeof' Babel helper is used more than once in your code. It's strongly recommended that you use the "external-helpers" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information (!) Error when using sourcemap for reporting an error: Can't resolve original location of error. src/common/helpers/setDefaultStory.ts: (1:9) [!] Error: 'storiesOf' is not exported by node_modules/@storybook/react/dist/client/index.js

My config

/* eslint-disable flowtype/require-valid-file-annotation, no-console, import/extensions */
import nodeResolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import flow from "rollup-plugin-flow";
import sourceMaps from "rollup-plugin-sourcemaps";
import typescript from 'rollup-plugin-typescript';
import svg from 'rollup-plugin-svg';

const commonPlugins = [
  flow({
    pretty: true
  }),
  sourceMaps(),
  nodeResolve({
    extensions: [".ts", ".tsx", ".js", ".jsx"]
  }),
  svg(),
  typescript(),
  babel({
    exclude: "node_modules/**"
  }),
  commonjs({
    namedExports: {
      react: [
        "cloneElement",
        "createFactory",
        "Component",
        "PropTypes",
        "createElement",
        "createContext"
      ],
      "react-dom": ["render"],
      "react-is": ["isElement", "isValidElementType", "ForwardRef"]
    }
  })
];

const globals = { react: "React", "react-dom": "ReactDOM" };

const configBase = {
  input: "./src/index.js",
  plugins: commonPlugins
};

const standaloneBaseConfig = {
  ...configBase,
  output: {
    file: "dist/styled-components-toolbox.js",
    format: "cjs",
    name: "sct",
    globals,
    sourcemap: true
  },
  plugins: configBase.plugins
};

export default standaloneBaseConfig;

How can resolve it?

ravecat commented 5 years ago

Found answer in docs

kevinforrestconnors commented 5 years ago

In case ravecat's link wasn't specific enough to help people, my specific solution was to add my source module directory to the resolve options:

resolve({
  customResolveOptions: {
    moduleDirectory: 'src'
  }
}),