Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

0

did you try to remove the include in commonJs

 commonjs(),
 sourcemaps(),

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda