NodeJS抛出非法指令:Mac OS上的4

时间:2017-04-24 07:54:37

标签: javascript node.js macos npm

每当我运行我的程序时,它会抛出非法指令:4而我不知道为什么。

我的代码:

glob('/path/music/*.mp3', function(error, files) {
for(var i = 0; i < files.length; i++) {
    songs.push(files[i]);
    console.log("Added file: " + files[i]);
}

console.log("Init player");
p = new player(songs)
    .on('playing', function(song){
        console.log("Playing now: " + song._name);
    })
    .on('playend', function(song){
        console.log("Next song....");
    })
    .on('error', function(song){
        console.log("Error:" + error);
    }).play();

    setTimeout(function(){ p.stop();},5000);


    console.log(JSON.stringify(p))
});

所以程序应该从我的路径播放一个mp3文件5秒钟然后停止播放但是在播放5秒后程序终止并且控制台输出为:

> node script.js
Playing now: music.mp3
Illegal instruction: 4

我正在使用来自npm:https://www.npmjs.com/package/player

的播放器包

3 个答案:

答案 0 :(得分:2)

问题在于speaker npm module中的player npm module

我在发言人GitHub repo "OSX - Illegal Instruction:4"

中发现了以下问题

解决方案是更新node_modules / speaker中的发言人:

<?php
  //check for referal links
  function referal()
  {
   $CI =& get_instance();
   $cookie_value_set = $CI->input->cookie('_tm_ref', TRUE) ? $CI->input->cookie('_tm_ref', TRUE) : '';
  if ($CI->input->get('ref', TRUE) AND $cookie_value_set == '') {
    // referred user so set cookie to ref=username
     $cookie = array(
    'name'   => 'ref',
    'value'  => $CI->input->get('ref', TRUE),
    'expire' => '7776000',
  );
    $CI->input->set_cookie($cookie);
    return TRUE;
   }elseif ($cookie_value_set == '') {
     $cookie = array(
    'name'   => 'ref',
    'value'  => 'sso',
    'expire' => '15552000',
  );
    $CI->input->set_cookie($cookie);
    return TRUE;

   }elseif ($cookie_value_set != '') {
     //already referred so ignore
    return TRUE;

   }else{
      return TRUE;
   }
  }
//end of hooks file
?>

(我还更新了版本1.2.4,您可能也需要这样做)

最后,我重建了播放器模块中的bin

npm install speaker --mpg123-backend=openal

这是我用来测试/调试的代码:

npm run build

希望有所帮助

答案 1 :(得分:0)

当您使用为不同系统或体系结构编译的二进制加载项时,通常会发生这种情况。

您可以尝试在应用目录中运行export class HomePage { datas:any = []; page:number =1; connected: Subscription; disconnected: Subscription; constructor(private toast: ToastController, private network: Network, public navCtrl: NavController, private wpapi: Wpapi) { this.getPosts(); } displayNetworkUpdate(connectionState: string){ //let networkType = this.network.type this.toast.create({ message: `You are currently ${connectionState}, please re connect your data`, duration: 3000 }).present(); } ionViewDidEnter() { this.disconnected = this.network.onDisconnect().subscribe(data => { console.log(data) this.displayNetworkUpdate(data.type); }, error => console.error(error)); } getPosts() { //this.page = '1'; //this.wpapi.index(this.page) this.wpapi.index(1) .subscribe(data => { this.datas = data; console.log(this.datas); }); } loadMore(infiniteScroll) { this.page++; this.wpapi.index( this.page ).subscribe( datas => { // Loads posts from WordPress API let length = datas["length"]; if( length === 0 ) { infiniteScroll.complete(); return; } for (var i = length - 1; i >= 0; i--) { this.datas.push( datas[i] ); } infiniteScroll.complete(); }); } doRefresh(refresher) { this.wpapi.index(1) .subscribe(data => { this.datas = data; refresher.complete(); }); } ionViewWillLeave(){ this.connected.unsubscribe(); this.disconnected.unsubscribe(); } } npm rebuild

您也可以删除npm install并从头开始运行node_modules

如果这没有用,那么它可能是您正在使用的某些模块的错误,或者它可能不支持您的架构,或者该模块使用的某些库未安装在您的系统正常。

答案 2 :(得分:0)

尝试以下操作:

npm uninstall player --save
npm uninstall speaker --save
npm install player --mpg123-backend=openal

对我有用。