0
我從這裏安裝webshot時:使用錯誤使用咕嚕聲,browserify建故宮webshot模塊
https://www.npmjs.org/package/webshot
:NPM安裝webshot
然後我有加「變種webshot =要求( 'webshot');」 JS文件,然後運行:
咕嚕打造
,通常它會編譯所有NPM模塊成lib.js文件,我可以在自己的項目上前端使用NPM模塊。
但我得到的錯誤:
>> Error: module "os" not found from "/Users/Feroze/Documents/meteor_apps/Bookmark_Website/.npm/node_modules/webshot/node_modules/tmp/lib/tmp.js"
File written to: ../lib/bundle.js
>> Error: module "constants" not found from "/Users/Feroze/Documents/meteor_apps/Bookmark_Website/.npm/node_modules/webshot/node_modules/tmp/lib/tmp.js"
File written to: ../lib/bundle.js
當運行咕嚕構建。我如何無法使用npm webshot模塊構建我的lib.js文件?只要我使用npm卸載webshot,它就可以很好地構建lib.js文件。
Gruntfile.coffee
module.exports = function(grunt) {
grunt.initConfig({
watch: {
build: {
files: ['./entrypoint.js', './package.json'],
tasks: ['browserify2'],
options: {
}
}
},
browserify2: {
compile: {
entry: './entrypoint.js',
compile: '../lib/bundle.js'
}
},
});
grunt.loadNpmTasks('grunt-browserify2');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('build', ['browserify2']);
};
的package.json
{
"name": "Template",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.3.3",
"grunt-contrib-uglify": "~0.4.0",
"browserify": "^4.1.9",
"grunt-browserify": "^2.1.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-webshot": "^0.3.0"
},
"dependencies": {
"curtsy": "0.0.1"
}
}
entrypoint.js
async = require('async')
webshot = require('webshot')
我無法重現你的錯誤,也許這是固定在一個更最近版本的browserify?如果你可以添加你的'package.json'和'Gruntfile.js',那會很有幫助。 – dylants
我認爲這個錯誤是因爲你不能在前端使用webshot包,對嗎?所以使用browserify,它不能編譯webshot,因爲缺少節點模塊。你有瀏覽器編譯webshot嗎? – nearpoint
是的我沒有問題在我的文件上運行'browserify'或'grunt-browserify',只需要'webshot'。你可以嘗試將它隔離到「browserify」嗎?例如,我創建了一個'index.js'文件,其中只包含'var webshot = require('webshot');'然後通過'browserify index.js> bundle.js'運行它,它工作正常。 – dylants