Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
How to prevent rollup from looking in parent node_modules folder

My Folder structure is the following:

/dev
  node_modules
  /lib
    node_modules
    rollup.config.js

and this my rollup.config.js

import babel from '@rollup/plugin-babel'
import image from '@rollup/plugin-image'
import json from '@rollup/plugin-json'
import commonjs from 'rollup-plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import sourcemaps from 'rollup-plugin-sourcemaps'
import postcss from 'rollup-plugin-postcss'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import del from 'rollup-plugin-delete'

export default {
    input: 'src/index.jsx',
    output: {
        dir: `dist`,
        format: 'es',
        exports: 'auto',
        sourcemap: true,
    },
    // inlineDynamicImports: true, //creates single output file but then there is no intellisense
    plugins: [
        del({ targets: 'dist/*' }),
        // replace({
        //     'process.env.NODE_ENV': JSON.stringify('development'),
        // }),
        peerDepsExternal(),
        nodeResolve({
            // modulesOnly: true, // crashes everything
            extensions: ['.js', '.jsx'],
        }),
        postcss({
            config: {
                path: './postcss.config.js',
            },
            extensions: ['.css', '.scss'],
            minimize: true,
            use: [
                [
                    'sass',
                    {
                        includePaths: ['./src/scss', './node_modules'],
                    },
                ],
            ],
        }),

        json(),
        image(),

        babel({
            exclude: 'node_modules/**',
            plugins: ['@babel/transform-runtime'],
            babelHelpers: 'runtime',
        }),
        commonjs({
            include: 'node_modules/**',
        }),
        sourcemaps(),
    ],
}

I build the code with rollup -c When the node_modules in /dev are installed the I get this error when I want to build the code: Error: 'default' is not exported by ../node_modules/prop-types/index.js, imported by ../node_modules/react-redux/es/components/Provider.js When I delete the /dev/node_modules folder and the build it again then everything works fine. How can I prevent rollup from looking in parent node_modules folder?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

did you try to remove the include in commonJs

 commonjs(),
 sourcemaps(),

about 4 years ago · Juan Pablo Isaza Report

0

The issue is not roll-up itself, but rather the plugin @rollup/plugin-node-resolve. The plugin attempts to resolve modules using the Node resolution algorithm, for using third party modules and that algo iterates through the parent directories, appending each one with "/node_modules" looking for a resolution. https://nodejs.org/api/modules.html#modules_all_together So the issue lies in having a monorepo and using this plugin. It's doesn't seem possible to stop this plugin behavior, however you can stop it from traversing specific module folders.

nodeResolve({
        resolveOnly: [/^(?!react$|react-dom$).*/]
    }),

Per the docs: https://github.com/rollup/rollup-plugin-node-resolve By using the resolveOnly option you can pass in regex expressions to block it from resolving specific modules, or pass in an array of strings specifying the only modules you want it to traverse. The above example does not traverse the react or react-dom modules in the parent folder.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!