Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not resolve memcpy when trying to roll-up a bundle #81

Open
btgoodwin opened this issue Nov 15, 2016 · 1 comment
Open

Could not resolve memcpy when trying to roll-up a bundle #81

btgoodwin opened this issue Nov 15, 2016 · 1 comment

Comments

@btgoodwin
Copy link

Part of this could be that I'm pretty new to these various module-generating tools that sprang up over the last two or three years. What I'm trying to do is roll up ProtoBuf and all of its dependencies along with my library using the rollup-plugin-commonjs and rollup-plugin-node-resolve plugins. The reason why I'm doing this is because there seems to be no way to use things like SystemJS or WebPack to deploy an app with my libraries, purely because ProtoBuf's requires of bytebuffer and a few other things. So I figured I would bundle everything into my library (ES2015) and move on. The reason I'm posting this issue here and not ProtoBuf is that when bundling it all up, the error I get is that 'memcpy' could not be resolved for bytebuffer-node.js.

The error I'm getting is:

Treating 'buffer' as external dependency
Could not resolve 'memcpy' from /var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/bytebuffer/dist/bytebuffer-node.js
Error: Could not resolve 'memcpy' from /var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/bytebuffer/dist/bytebuffer-node.js
at Error (native)
at /var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js:78:21
at /var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:46:14
at process (/var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:173:43)
at ondir (/var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:188:17)
at load (/var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:69:43)
at onex (/var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:92:31)
at /var/redhawk/sdr/rest-python/apps/angular-redhawk/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:123:15)

The configuration I'm using is:

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

export default {
  entry: `dist/index.js`,
  context: 'this',
  sourceMap: (process.env.NODE_ENV === 'test') ? 'inline' : true,
  moduleId,
  moduleName,
  plugins: [
    nodeResolve({ main: true }),
    commonjs({
      include: 'node_modules/**',
      sourceMap: false
    })
  ],
  targets: [
    { dest: `dist/bundles/${moduleId}.umd.js`, format: 'umd' },
    { dest: `dist/bundles/${moduleId}.mjs`, format: 'es' },
  ],
  globals: {
    '@angular/core': '_angular_core',
    '@angular/common': '_angular_common',
    '@angular/http': '_angular_http',
    'rxjs/Observable': '_rxjs_Observable',
    'rxjs/Subject': '_rxjs_Subject',
    'rxjs/add/operator/map': '_rxjs_add_operator_map',
    'rxjs/add/operator/catch': '_rxjs_add_operator_catch'
  },
  external: [
    '@angular/core',
    '@angular/common',
    '@angular/http',
    'rxjs/add/operator/map',
    'rxjs/add/operator/catch',
    'rxjs/Observable',
    'rxjs/Subject'
  ]
};
@sjonany
Copy link

sjonany commented Dec 27, 2016

I got around this error by inspecting this line in bytebuffer-node.js
“ memcpy = null; try { memcpy = require("memcpy"); } catch (e) {}”
Looks like memcpy is an optional dep, but rollup might be harvesting all the require statements statically.

When I remove the try statement, the error disappears -- I still have other problems from getting aot + rollup + protobufjs to work ;), but at least this particular error has a workaround.

EDIT: This error also disappeared once I added rollup-plugin-node-globals and rollup-plugin-node-builtins to my rollup plugin, following this:
rollup/rollup#1051 (comment)

Again, got a different error, but I think it's a rollup issue instead of bytebuffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants