Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 Respostas
Responde à pergunta

0

did you try to remove the include in commonJs

 commonjs(),
 sourcemaps(),

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda