Giter Site home page Giter Site logo

rollup / rollup-plugin-node-resolve Goto Github PK

View Code? Open in Web Editor NEW
468.0 468.0 96.0 406 KB

This module has moved and is now available at @rollup/plugin-node-resolve / https://github.com/rollup/plugins/blob/master/packages/node-resolve

License: MIT License

JavaScript 100.00%

rollup-plugin-node-resolve's Introduction

npm version node compatibility install size code coverage backers sponsors license Join the chat at https://is.gd/rollup_chat

Rollup

Overview

Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application. It uses the standardized ES module format for code, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. Rollup can optimize ES modules for faster native loading in modern browsers, or output a legacy module format allowing ES module workflows today.

Quick Start Guide

Install with npm install --global rollup. Rollup can be used either through a command line interface with an optional configuration file or else through its JavaScript API. Run rollup --help to see the available options and parameters. The starter project templates, rollup-starter-lib and rollup-starter-app, demonstrate common configuration options, and more detailed instructions are available throughout the user guide.

Commands

These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.

For browsers:

# compile to a <script> containing a self-executing function
rollup main.js --format iife --name "myBundle" --file bundle.js

For Node.js:

# compile to a CommonJS module
rollup main.js --format cjs --file bundle.js

For both browsers and Node.js:

# UMD format requires a bundle name
rollup main.js --format umd --name "myBundle" --file bundle.js

Why

Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place isn't necessarily the answer. Unfortunately, JavaScript has not historically included this capability as a core feature in the language.

This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the --experimental-modules flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to write future-proof code, and you also get the tremendous benefits of...

Tree Shaking

In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.

For example, with CommonJS, the entire tool or library must be imported.

// import the entire utils object with CommonJS
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);

But with ES modules, instead of importing the whole utils object, we can just import the one ajax function we need:

// import the ajax function with an ES import statement
import { ajax } from 'node:utils';

var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);

Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit import and export statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.

Compatibility

Importing CommonJS

Rollup can import existing CommonJS modules through a plugin.

Publishing ES Modules

To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ES-module-aware tools like Rollup and webpack will import the ES module version directly.

Contributors

This project exists thanks to all the people who contribute. [Contribute]. . If you want to contribute yourself, head over to the contribution guidelines.

Backers

Thank you to all our backers! πŸ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Special Sponsor

TNG Logo

TNG has been supporting the work of Lukas Taegert-Atkinson on Rollup since 2017.

License

MIT

rollup-plugin-node-resolve's People

Contributors

arantes555 avatar bterlson avatar eventualbuddha avatar georgetaveras1231 avatar ggalansmithee avatar guillaumevincent avatar guybedford avatar joeldenning avatar jonhartnett avatar kaksmet avatar keithamus avatar kenjio avatar kocal avatar lammas avatar leebyron avatar linusu avatar lukastaegert avatar ma2ciek avatar manucorporat avatar maranomynet avatar mcshaman avatar mikeharder avatar mislav avatar nicolashenry avatar nolanlawson avatar notwoods avatar rich-harris avatar shellscape avatar trysound avatar vinkla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rollup-plugin-node-resolve's Issues

Bundle Promise polyfill

Without a Promise polyfill, this plugin can't be use in Node 0.10. This package currently does new Promise() without loading a polyfill when needed.

Output requires module which isn't in the dependency chain

I have the uuid module as a dependency, and I have browser: true in the nodeResolve plugin config.

The uuid module has a uuid.js main file, which has require('./lib/rng').

However, there are two different lib files, one which gets loaded in the browser:

"browser": {"./lib/rng.js": "./lib/rng-browser.js"}

With rollup, my umd output somehow has require('crypto')) and the rng-browser.js code which breaks my script. Since I'm using requirejs and crypto wasn't a module, I get:

require.min.js:1 Uncaught Error: Script error for "crypto"

The only reference to require('crypto') in the source files is the original ./lib/rng.js which was replaced, so I'm confused where the name crypto is coming from.

I do see Treating 'crypto' as external dependency during the build process, but uuid is the only module I use that references crypto - which I confirmed by building a file with only import uuid from 'uuid';

react\react.js does not export default

I have React installed in node_modules and import it in ./src/main.js, with such configs:

{
  entry: './src/main',
  dest: './build/bundle.rollup.js',
    plugins: [
      npm({
        main: true
      }),
      commonjs({
        include: 'node_modules/**'
      }),
      babel({
        exclude: 'node_modules/**'
      })
  ],
  format: 'iife'
}

But it ran into some issue:

Module *\react\react.js does not export default (imported by *\src\main.js)

Without rollup-plugin-npm it works but sure it does not include React in the Rollup bundle.

Error with entry file paths beginning with ./

Does not work:

rollup --config --output app/js/index.js ./js/index.js

Works:

rollup --config --output app/js/index.js js/index.js

rollup.config.js

import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
  plugins: [
    nodeResolve(),
    commonjs()
  ]
};

Error message:

Path must be a string. Received undefined
TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1148:7)
    at resolveId$1 (/Users/moberlehner/Sites/vagrant/devbox/modularis/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js:42:15)
    at /Users/moberlehner/Sites/vagrant/devbox/modularis/node_modules/rollup/src/utils/first.js:8:31
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Function.Module.runMain (module.js:577:11)
    at startup (node.js:160:18)
    at node.js:456:3

Is this an error or should I use paths not beginning with ./ in general?

Documentation for default values for options

It would be a huge improvement if the README would list the default values of each option for the plugin.

It's kind of cumbersome to have to read the source to figure those out.

(Same applies to a lot of the other rollup plugins.)

Use node-resolve to resolve files

node-resolve is a widely used module to do node/npm module path resolution. This plugin should probably use it. It'd fix an issue for me, where import foo from 'bar/foo'; fails to resolve to node_modules/bar/foo/index.js if that's the file node would have resolved given the same path to a require call.

jsnext:browser?

I have a package that targets Node and the browser but not isomorphicallyβ€”I have a Node-specific script and a browser-specific script. I wish to bundle each of these in CJS and ES6 formats. How may I do this? Seems like jsnext:browser is required:

"main": "dist/node/index.js",
"jsnext:main": "dist/node/index.es2015.js",
"browser": "dist/browser/index.js",
"jsnext:browser": "dist/browser/index.es2015.js"

How to handle optionalDependencies

Some packages with optionalDependencies will require them within try-catch:

var memcpy = null; try { memcpy = require("memcpy"); } catch (e) {}
if (memcpy) //...

Rolling them up will throw Cannot find module 'memcpy'.

How to ignore these packages entirely? The 'skip' option only treat them as external.

Problem with nested imports

Repository to reproduce: https://github.com/scola84/rollup-resolve-bug

If I import only one of two exports (server), the second order import (value) from the omitted import (client) is resolved anyway.

Expected result:

'use strict';

var server = {
    value: 'server'
};

console.log(server);

Actual result:

'use strict';

const value = 42;

var server = {
    value: 'server'
};

console.log(server);

Is my expectation wrong or is there something wrong with the plugin?

npm-link

I have a library that bundles together several rollup-friendly libraries.
Everything works very well, but when I use npm-link on any of the libraries things don't work as expected anymore.

The resulting bundle includes imported libraries more than once.
Not a big deal, this is development issue, but the bundle can get quite big during development

Why check for `default` on commonjs modules?

I'm curious:
Since CommonJS module's don't have the concept of an explicit "default" export...

Why does this:

import foo from './_js/commonjs-module.js';
alert(foo.answer);

...result in this?

var module$1 = __commonjs(function (module) {
module.exports = {
  msg: 'This is a CommonJs module',
  answer: 42,
};
});
var foo = (module$1 && typeof module$1 === 'object' && 'default' in module$1 ? module$1['default'] : module$1);
alert(foo.answer);

I mean, why not simply say var foo = module$1; since this seems to be the inevitable end result every time anyway?

Error bundling babel modules

My rollup plugins settings for grunt-rollup

        rollup: {
            options: {
                format: 'cjs',
                banner: "<%= meta.banner %>",
                plugins: [
                    replace(build),
                    babel(),
                    npm({
                        jsnext: true,
                        main: true
                    }),
                    commonjs({
                        include: 'node_modules/**'
                    })
                ]
            },
            files: {
                src: 'src/js/embed.es6',
                dest: 'src/embed.js'
            }
        }

Error

Warning: 'import' and 'export' may only appear at the top level (7:13) in /Users/ritz078/projects/embed.js/node_modules/babel-runtime/regenerator/index.js

I am using babel v5 and rollup-plugin-babel v1.0

react/react.js does not export PropTypes

I am trying to import React along with PropTypes in a file called App.js which gets included by the file main.js. This is what I have in App.js:

import React, { PropTypes } from 'react';

I am getting the following error:

*/node_modules/react/react.js does not export PropTypes (imported by */src/js/App.js)

Here is my gulp task

gulp.src('./src/js/main.js', { read: false })
    .pipe($.rollup({
      plugins: [
        commonjs({
          include: 'node_modules/**'
        }),
        nodeResolve({
          main: true
        }),
        babel({
          exclude: 'node_modules/**',
          "presets": ["react", "es2015-rollup"]
        }),
      ],
      format: 'iife'
    }))
    .pipe(gulp.dest('./dist/js'))

I also replicated this error in this gist which I got from a previous issue that seemed to be related

Customize path to node_modules

It's possible rollup is being used by an app with different node modules directory, it's also possible it's being used from within another build step which necessitates a custom directory.

Rollup generate bundles that require dependencies that are not needed.

I am trying to use rollup with an existing node project (all dependencies are called using require)
One of the dependecy in nunjucks a well known templating engine.

Rollup seem to resolve a dependency of nunjucks: fsevents via chokidar, which is a OS dependent module not used under Linux.

Same problem with knex module which requires sqlite3 which is not used in this case.

Of course we can just ignore this modules in conf, but shouldn't it be smart enough to do it by itself?

[Edit] Even if you skip this modules, the generate bundle.js (launched with node) crash saying these modules are missing.

Turning off "main" Option Breaks Local Imports

If I turn off the main option, thus excluding non-ES6 npm packages, then I can no longer include my own local JS files that are not part of an npm package at all. They fail with an error like

Package ./foobar (imported by C:\Users\tc\Documents\temp\main.js) does not have a module or jsnext:main field. You should either allow legacy modules with options.main, or skip it with options.skip
= ['./foobar'])
Error: Package ./foobar (imported by C:\Users\tc\Documents\temp\main.js) does not have a module or jsnext:main field. You should either allow legacy modules with options.main, or skip it with option
s.skip = ['./foobar'])
    at Error (native)
    at Object.packageFilter (C:\Users\tc\Documents\temp\node_modules\rollup-plugin-node-resolve\dist\rollup-plugin-node-resolve.cjs.js:69:22)
    at C:\Users\tc\Documents\temp\node_modules\resolve\lib\async.js:118:32
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)

I am seeing this with rollup v0.34.13 and rollup-plugin-node-resolve v2.0.0

Here is a Gist that minimally reproduces the issue: https://gist.github.com/arashikou/447e145ed5d104060b56d2be87ed4b7e

Tree shaking not applied for node modules

When i use rollup with node_modules unused exports also appear in the bundled file.
Shouldnt it apply tree shaking also for node_modules? Or just im making something wrong.
Of course these unused exports disappear when uglified, but according to the official Rollup examples these should not be there before uglify.

I made an example repo to show my problem.
https://github.com/blacksonic/es2015-tree-shaking

I use RxJS, and it always applies operators for example, which makes the size bigger. Even if i uglify.

Skipping `jsnext: true` for a single module?

I have a particular module that does define the jsnext field, which is lovely, except it's using features that my ES2015 compiler can't handle at this point in time. I'd like to make that single module use the main property instead, but keep jsnext on for all the other modules: is this possible?

Uses wrong package.json for '/full/path/to/my/packageDir'

.
└── foo
    β”œβ”€β”€ bar
    β”‚Β Β  β”œβ”€β”€ index.js
    β”‚Β Β  └── package.json
    β”œβ”€β”€ index.js
    └── package.json

If you do:

import pkg from '/full/path/to/foo/bar';

then this module will improperly use foo/package.json (e.g. to check for "main" and "jsnext:main") instead of bar/package.json.

Couldn't find preset "es2015-rollup" relative to directory "[...]rollup-plugin-node-resolve/src"

I do not use the es2015-rollup preset in my project. As so i do get the error:
Couldn't find preset "es2015-rollup" relative to directory "[...]rollup-plugin-node-resolve/src"
when using the node-resolve plugin.

As a workaround I npm install the preset myself, but I do think that could be easily fixed when putting
"babel-preset-es2015-rollup": "^1.0.0"
inside the dependencies instead of devDependencies.

Example is broken?

First of all great concept and nice work on rollup.js. Tried to setup a minimal example with a few imports from node_modules, however rollup with the options as per the provided example is dead in the water. .then (to write the bundle) seems to never be called. Without the plugin everything seems to work as expected.

Please document usecases

Hello there!
I'm trying to get rollup to work with node modules. The README doesn't give me any clue whether or not I need that so I can simply require/import npm modules.

I'd appreciate efforts to clarify why or why not I need this plugin. Thanks in advance.

Could not resolve 'vue'

rollup.config.js

import nodeResolve from 'rollup-plugin-node-resolve'

export default {
    entry: 'src/bootstrap.js',

    plugins: [
        nodeResolve()
    ],

    dest: 'dist/app.js'
}

What I've got:

Could not resolve 'vue' from /Users/belyaev/www/vuex-tutorial/src/bootstrap.js
Error: Could not resolve 'vue' from /Users/belyaev/www/vuex-tutorial/src/bootstrap.js
    at Error (native)
    at /Users/belyaev/www/vuex-tutorial/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js:78:21
    at /Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:46:14
    at process (/Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:173:43)
    at ondir (/Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:188:17)
    at load (/Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:92:31)
    at /Users/belyaev/www/vuex-tutorial/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki

jsnext:main directory support?

This isn't strictly node resolution, but I figure this is as close a place as any.

Situation:

Angular2's codebase distributes es modules in a subdirectory /esm and denotes the jsnext:main field in the package.json.

This works well, except for our compiler-generated code outputs code that uses deep imports (which is a much longer story...), so whereas most userland code does stuff like:

import {Component} from '@angular/core'

which resolves fine via jsnext:main and this plugin, our generated code does stuff like

import {ViewFactory} from '@angular/core/src/some/deep/path'

which of course fails to resolve properly. I implemented a simple plugin that did a path rewrite, but that seems to confuse rollup's symbol resolution, so I end up with multiple copies of imports, which breaks all kinds of things. None of this is particularly unexpected.

On a whim, I dug into the source of this plugin today and moved my dirty hack into the _resolveId function, leveraging path-resolve's pathFilter function to rewrite the path internally, relative to the jsnext:main file, and lo and behold my issue is solved.

Would a PR be accepted to enable this behavior? Or should this already work? Or is it out of scope of this plugin?

tldr: basically, i want to leverage jsnext:main to rewrite all imports into a package relative to the es module main entry point, rather than just the main.

Problem with nested imports

I have the plugin working fine with initial imports of npm modules, however, when these modules have external dependencies, they are not resolved. I get the 'required is not defined' error in the devtools console.

import * as plumber from 'gulp-plumber';

compiles to

var through2 = require('through2'); 
var EE = require('events').EventEmitter;
var gutil = require('gulp-util'); 

Any ideas on how I could fix this? (pretty sure it's not an issue with the plugin, just something I'm not quite getting). It could also be an issue with commonjs plugin for roll up, but I'm not sure.

Prefers `browser` field over `jsnext:main`

With the config

...
nodeResolve({
    jsnext: true,
    browser: true,
}),
...

rollup will prefer the browser field over the jsnext:main of a dependency.

For example, trying to use D3 will result in it using the bundled browser version giving you import/export errors. (D3 package.json)

Looking at the code, I'm assuming it will prefer browser over everything.

Is this expected behaviour? Certainly could do with at least documenting as a gotcha.

Thanks

Module PATH does not export NAME (imported by PATH)

I'm trying to import an external NPM dependency with rollup. In my case β€” but I also tried it with other libraries β€” it's lory.js, which also uses jsnext:main in the package.json:

npm install --save lory.js
// main.js
import { lory } from 'lory.js';

const loryInstance = lory(document.querySelector('.js-carousel'));

My rollup.config.js looks very similar to what's described in the rollup-plugin-babel documentation:

import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
  entry: 'main.js',
  dest: 'bundle.js',
  plugins: [
    nodeResolve(),
    babel({
      exclude: 'node_modules/**'
    })
  ]
};

Then, whenever I run rollup --config rollup.config.js, I get this error message:

The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten
Module PATH/node_modules/lory.js/dist/lory.js does not export lory (imported by PATH/main.js)

Is this a bug or the expected behaviour?

As a side note: I also tried to bundle it with browserify and it works, so it doesn't seem to be a problem with lory itself.

Should show source location with preferBuiltins

When source contains builtin modules, like util, below warning will show:

preferring built-in module 'util' over local alternative at '/home/1111hui/public_html/node_modules/util/util.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning

It shows the local module position,
But don't show the exact source location, should it show?

Browser resolve fails in Node 6: opts.filename is undefined

This error is thrown only on Node 6, only when using rollup-plugin-node-resolve, and only when using browser: true. Those three conditions need to be met in order to reproduce this bug.

The offending line of of code is in node-browser-resolve (opts.filename is undefined), so it's possible this bug doesn't exist here but rather in that repo. I wasn't sure, so I'm filing it here.

I have a gist to reproduce.

Steps:

git clone https://gist.github.com/e029b935459d4cdb5097d1a74485be63.git gist && cd gist
npm i && node build.js

The error received is:

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.dirname (path.js:1324:5)
    at resolve (/Users/nolan/Desktop/repro-rollup-bug/node_modules/browser-resolve/index.js:218:21)
...

More flexible 'main' option

Suggestion: allow the main option to be provided as an array.

{
  include: 'node_modules/**',
  jsnext: true,
  main: ['foo', 'bar'] // use main (or index.js) only if the module is in this whitelist
}

Reasoning: in general, I want to default to trusting anything with a jsnext:main field is probably safe to bundle. But for everything else, I want to default to keeping it external until I've verified it's safe to bundle.

iife bundle attempt with umd dependency yielding 'does not export default'

Specifically, I'm importing bloodhound.js which appears to be a umd file.

Since I'm using rollup format: iife, is there something else I need to do to get the bloodhound UMD into a form that I can include with rollup?

Here's my current config:

//Executing rollup with options: 
{
    entry: 'app/assets/javascripts/application.js',
    sourceMap: true,
    format: 'iife',
    plugins: [
        babel({
            babelrc: false,
            presets: ['es2015-rollup']
        }),
        nodeResolve({
            // use "jsnext:main" if possible
            // – see https://github.com/rollup/rollup/wiki/jsnext:main
            jsnext: true,

            // use "main" field or index.js, even if it's not an ES6 module (needs to be converted from CommonJS to ES6
            // – see https://github.com/rollup/rollup-plugin-commonjs
            main: true,

            //skip: [ 'some-big-dependency' ], // if there's something your bundle requires that you DON'T want to include, add it to 'skip'

            // By default, built-in modules such as `fs` and `path` are treated as external if a local module with the same name
            // can't be found. If you really want to turn off this behaviour for some reason, use `builtins: false`
            builtins: false,

            // Some package.json files have a `browser` field which specifies alternative files to load for people bundling
            // for the browser. If that's you, use this option, otherwise pkg.browser will be ignored.
            browser: true,

            // not all files you want to resolve are .js files
            extensions: [ '.js', '.json' ]
        })
    ],
    dest: 'public/assets/debug/application.js'
}

Error with wrong local import, leads to recursive loop

Update: seems to be related to rollup/rollup#1025. But the proposed solution does not solve the issue: it no longer loops, but (correct) updates are not propagated during watch.


My understanding was that rollup-plugin-node-resolve resolves files in node_modules. Nevertheless it raises an error if a local file import is incorrect. The error leads to a recursive loop, so the watch that I have running crashes. I then need to quit the process, and often kill the webserver process that is still running. So I would call this a crashing bug.

It happens when

import {Page} from '../styles';

is written, instead of

import {Page} from './styles';

This is what is written to the console:

Could not resolve '../styles' from /Users/arthur/project/master/app/index.js
Error: Could not resolve '../styles' from /Users/arthur/project/master/app/index.js
    at Error (native)
    at /Users/arthur/project/master/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js:78:21
    at /Users/arthur/project/master/node_modules/resolve/lib/async.js:55:18
    at load (/Users/arthur/project/master/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/arthur/project/master/node_modules/resolve/lib/async.js:92:31)
    at /Users/arthur/project/master/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:123:15)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki
bundling...
Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at deepClone (/Users/arthur/project/master/node_modules/rollup/src/utils/object.js:24:26)
    at deepClone (/Users/arthur/project/master/node_modules/rollup/src/utils/object.js:36:18)
     etc.

My config setting is

resolve({
    jsnext: true,
    main: true
})

Node Resolve not finding Browser.js (or browser.min.js)

I was trying to bundle React-Komposer into my react project but when I try to use CommonJS & Node Resolver to import it, I get thrown the following error:

[Error: Module C:\Users\*******.******\Desktop\*******\JSApps\node_modules\react-komposer\index.js does not export compose (imported by C:\Users\*****.******\Desktop\*******\JSApps\containers\******UI.js)]

The Rollup build looks like this:

rollup.rollup({
    entry: appPath + '/'+folder+'/main.js',
    plugins: [
        nodeResolve({
            skip: ['react','react-dom'],
            jsnext: true,
            main: true,
            browser: true
        }),
        commonjs(),
        babel({
            "presets": ["react", "es2015-rollup"],
            comments: false
        }),
        uglify()
    ]
})

File Directory for the node module looks like this:

  • 0 react-komposer
    1. index.js
    1. dist
  • 2.1 browser.js
  • 2.2 browser.min.js
  • 2.3 index.js
  • 2.4 util.js
  • 2.5 window_bind.js

The root index.js just contains this line of code:

module.exports = require('./dist/index');

Rename this plugin

npm is a misnomer. All this plugin is really doing is wrapping node-resolve and browser-resolve. I think it would probably make sense to rename this package to rollup-plugin-node-resolve. Thoughts?

Rollup and prefixed NPM packages

Hi,

When trying to use rollup on an app that requires a package with the format @org/foo (with both main and jsnext:main props set), I am getting the following output:

Treating '@org/foo' as external dependency
Error: Cannot find module '@org/foo' from '/Users/me/git/my-repo'
    at /Users/me/git/my-repo/node_modules/resolve/lib/async.js:46:17
    at process (/Users/me/git/my-repo/node_modules/resolve/lib/async.js:173:43)
    at ondir (/Users/me/git/my-repo/node_modules/resolve/lib/async.js:188:17)
    at load (/Users/me/git/my-repo/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/me/git/my-repo/node_modules/resolve/lib/async.js:92:31)
    at /Users/me/git/my-repo/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

Any idea why?

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.