Rollup.js未解析的依赖项

时间:2017-01-05 22:09:00

标签: javascript dependencies rollupjs

我正在尝试将rollup.js合并到一个项目中。目前我收到控制台下面提供的警告(未解决的依赖项),我不知道为什么或如何解决它:

'fs' is imported by node_modules\filereader\FileReader.js, but could not be resolved – treating it as an external dependency

'fs' is imported by  commonjs-external:fs, but could not be resolved – treating it as an external dependency

preferring built-in module 'punycode' over local alternative at 'C:\Users\Ryan\OneDrive\Projects\Custom Coding\Zapier\Ryan Test\node_modules\punycode\punycode.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning

preferring built-in module 'punycode' over local alternative at 'C:\Users\Ryan\OneDrive\Projects\Custom Coding\Zapier\Ryan Test\node_modules\punycode\punycode.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning

以下是需要FileReader和https:

的test.js脚本
var FileReader = require('filereader');
var https = require('https');

最后执行创建捆绑包的rollup.config.js文件:

var rollup = require('rollup');

var commonjs = require('rollup-plugin-commonjs');
var nodeResolve = require('rollup-plugin-node-resolve');
var globals = require('rollup-plugin-node-globals');
var builtins = require('rollup-plugin-node-builtins');

// build bundle
rollup
  .rollup({
    entry: 'test.js',
    plugins: [
      nodeResolve(),
      commonjs(),
      globals(),
      builtins()
    ]
  })
  .then(bundle => bundle.write({
    dest: 'rollupBundle/bundle.js',
    format: 'cjs'
  }))
  .catch(err => console.log(err.stack));

1 个答案:

答案 0 :(得分:8)

CLI将生成更多信息性警告 - 如果您更新配置文件以使用标准表单,则可以使用rollup -c代替它,它通常会为您提供帮助诊断问题的URL。

这是一个配置文件,其中包含必要的更改以压制这些警告:

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

export default {
  entry: 'test.js',
  dest: 'rollupBundle/bundle.js',
  format: 'cjs',
  external: [ 'fs' ], // tells Rollup 'I know what I'm doing here'
  plugins: [
    nodeResolve({ preferBuiltins: false }), // or `true`
    commonjs(),
    globals(),
    builtins()
  ]
};