Rollup.js未解决的依赖项 [英] Rollup.js unresolved dependencies

查看:553
本文介绍了Rollup.js未解决的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to incorporate rollup.js into a project. Currently I am getting the warnings provided below in the console (unresolved dependencies) and I am not sure why or how to fix it:

'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脚本:

Here is the test.js script requiring FileReader and https:

var FileReader = require('filereader');
var https = require('https');

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

Finally the rollup.config.js file which executes creating the bundle:

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));


推荐答案

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

The CLI will generate more informative warnings — if you update your config file to use the standard form, then you can use rollup -c instead and it will often give you a URL to help diagnose issues.

这里是一个配置文件,其中进行了必要的更改以抑制那些警告:

Here's a config file with the necessary changes to squelch those warnings:

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()
  ]
};

更新:正式汇总插件现在位于npm上的@rollup命名空间下,如果安装上述两个版本,则会显示 npm WARN deprecated。消息,所以改为安装较新的版本:

UPDATE: The "official" Rollup plugins are now under the @rollup namespace on npm, if you install the two versions mentioned above you will get an "npm WARN deprecated" message, so instead install the newer versions instead:

npm install @rollup/plugin-commonjs --save-dev
npm install @rollup/plugin-node-resolve --save-dev

然后使用它们:

import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';

这篇关于Rollup.js未解决的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆