rollup-plugin-node-resolve not resolving dependency
brucou opened this issue · 5 comments
This is going to be a pretty easy question, but after reading and rereading documentation, and a thousand different trials, I still cannot get my library to resolve my dependencies.
Directory hierarchy is :
root
|-- package.json
|-- rollup.config.js
|-- node_modules
|-- fast-json-patch
|-- fp-rosetree
|-- deep-equal
Rollup config file is :
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from "rollup-plugin-terser";
export default {
input: 'src/index.js',
output: {
file: 'dist/transducer.umd.js',
format: 'umd',
name: 'StateTranducer',
},
plugins: [
resolve({
module: true, // Default: true
jsnext: false, // Default: false
main: true, // Default: true
browser: true, // Default: false
extensions: [ '.mjs', '.js', '.jsx', '.json' ],
preferBuiltins: false, // Default: true
// Lock the module search in this path (like a chroot). Module defined
// outside this path will be marked as external
// jail: '/my/jail/path', // Default: '/'
// Set to an array of strings and/or regexps to lock the module search
// to modules that match at least one entry. Modules not matching any
// entry will be marked as external
only: [
/^fp-rosetree$/,
], // Default: null
modulesOnly: false, // Default: false
}),
commonjs({
include: ['node_modules/**', "node_modules/deep-equal/**"],
}),
terser()
]
};
then my code has
import { applyPatch } from "fast-json-patch/"
The fast-json-patch
library in its code features a var _equals = require('deep-equal');
. In terminal, the error message I get is :
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
deep-equal (guessing 'deepEqual')
As the module deep-equal
can be found in node_modules
directory, I expect rollup to be able to resolve it. I even ran npm install
in node_modules/fast-json-patch
to install deep-equal
in the node_modules/fast-json-patch/node_modules
but that still failed to produce any result.
Note that fp-rosetree
is correctly resolved, and fast-json-patch is a commonjs module, as you can guess from the rollup config.
What can I be missing?
I've hit a brick wall with this, tried debugging the source code to little success.
Here is my config
// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
export default {
input: './src/lib/response.js',
output: {
file: './dist/response.js',
format: 'umd'
},
name: 'peptide.io-core-calculations',
plugins: [
resolve({
jsnext: true, // Default: false
main: true, // Default: true
browser: true, // Default: false
only: [ 'node_modules/joi/**', 'node_modules/memoizee/**' ]
})
]
};
My current suspicion is that rollup-plugin-node-resolve is using the input file's root directory to resolve node_modules, but for tonight I can't figure out how to resolve this. (edit: I'm tired, I'm probably wrong.)
Here is my experiment I tried inserting into the source code to correct the id
,
const firstChar = importee.charAt(0);
const isRequireModule = firstChar >= 'a' && firstChar <= 'z';
if (isRequireModule) {
id = path.resolve(options.modulesDirectory, importee);
}
for now, I'm stumped.
@guybedford could you shed a little light into how to resolve node_modules relative to the root project directory?
For a little more context, there is no issue using require('foobar'), but when importing defaults with es6 such as import foo from 'foobar
or import { default as foo } from 'foobar'
Edit: It seems my specific issue may be unrelated to this, I ended up including the commonjs plugin after resolve, then because there was an issue parsing the package.json of "Joi", I made use of a browserified version of the package.
The code path - https://github.com/rollup/rollup-plugin-node-resolve/blob/master/src/index.js#L87 needs to be removed. It may be as simple as that one line, setting the importer
to the cwd. It will need a test.
I tried to reproduce it and got no errors. Can be closed now.
still having this issue with imported node_modules in default svelte/template app ... uuidv4 needs rng which needs crypto, and it doesn't compile. ugh