2017-01-05 323 views
1

我正在嘗試將rollup.js合併到項目中。目前,我正在在控制檯(未解決的依賴)下面提供的警告,我不知道爲什麼或如何解決它: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 

這裏是test.js腳本需要的FileReader和https:

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

回答

2

的CLI會產生更多的信息警告 - 如果你更新你的配置文件,以使用STA ndard表單,那麼您可以使用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() 
    ] 
}; 
+0

感謝豐富,我認爲這會工作。 –

+0

任何想法,爲什麼我會得到一個錯誤,說https沒有基於上述定義?這不是彙總錯誤,而是來自我試圖部署的環境的錯誤。 –

+0

很難說沒有repro來調查,對不起 –