Javascript 使用webpack导入ar.js

Javascript 使用webpack导入ar.js,javascript,node.js,webpack,ar.js,Javascript,Node.js,Webpack,Ar.js,我正在做一个基于three.js的项目,我正在尝试使用ar.js库添加增强现实支持。该项目基于Node,与Webpack捆绑,使用Babel loader。 这是我的webpack.config.js: const HtmlWebpackPlugin = require("html-webpack-plugin"); const webpack = require("webpack"); const {CleanWebpackPlugin} = require("clean-webpack-pl

我正在做一个基于three.js的项目,我正在尝试使用ar.js库添加增强现实支持。该项目基于Node,与Webpack捆绑,使用Babel loader。 这是我的webpack.config.js:

const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");

const path = require('path');

module.exports = {
  entry: './src/main.js',
  output: {
      filename: '[name].bundle.js',
      path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env']
            }
          }
        },
        {
            test: /\.css$/,
            use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
        },
      ]
  },
  resolve: {
    alias: {
      'three': path.join(__dirname, 'node_modules/three/build/three.min.js'),
    }
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: "Webpack Output",
    }),
    new CleanWebpackPlugin(),
    new webpack.ProvidePlugin({
      'THREE': 'three',
    })
  ],
  devServer: {
    contentBase: './dist',
    open: true
  },

};
在添加任何代码之前,我尝试从本地文件夹导入ar.js库,该文件夹在从官方github存储库下载后添加到项目中:

当我构建项目时,会出现以下错误:

ERROR in ./src/AR.js-master/three.js/build/ar.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /webpack-demo/src/AR.js-master/three.js/build/ar.js: Identifier '_malloc' has already been declared (19:519)

  17 | 
  18 | // EMSCRIPTEN_END_ASM
> 19 | (Module.asmGlobalArg,Module.asmLibraryArg,buffer);var _i64Subtract=Module["_i64Subtract"]=asm["_i64Subtract"];var __GLOBAL__sub_I_bind_cpp=Module["__GLOBAL__sub_I_bind_cpp"]=asm["__GLOBAL__sub_I_bind_cpp"];var _fflush=Module["_fflush"]=asm["_fflush"];var __GLOBAL__sub_I_ARToolKitJS_cpp=Module["__GLOBAL__sub_I_ARToolKitJS_cpp"]=asm["__GLOBAL__sub_I_ARToolKitJS_cpp"];var _i64Add=Module["_i64Add"]=asm["_i64Add"];var _memset=Module["_memset"]=asm["_memset"];var runPostSets=Module["runPostSets"]=asm["runPostSets"];var _malloc=Module["_malloc"]=asm["_malloc"];var _memcpy=Module["_memcpy"]=asm["_memcpy"];var ___getTypeName=Module["___getTypeName"]=asm["___getTypeName"];var _bitshift64Lshr=Module["_bitshift64Lshr"]=asm["_bitshift64Lshr"];var _free=Module["_free"]=asm["_free"];var ___errno_location=Module["___errno_location"]=asm["___errno_location"];var _bitshift64Shl=Module["_bitshift64Shl"]=asm["_bitshift64Shl"];var dynCall_iiii=Module["dynCall_iiii"]=asm["dynCall_iiii"];var dynCall_viiiii=Module["dynCall_viiiii"]=asm["dynCall_viiiii"];var dynCall_dii=Module["dynCall_dii"]=asm["dynCall_dii"];var dynCall_vid=Module["dynCall_vid"]=asm["dynCall_vid"];var dynCall_di=Module["dynCall_di"]=asm["dynCall_di"];var dynCall_i=Module["dynCall_i"]=asm["dynCall_i"];var dynCall_vi=Module["dynCall_vi"]=asm["dynCall_vi"];var dynCall_vii=Module["dynCall_vii"]=asm["dynCall_vii"];var dynCall_ii=Module["dynCall_ii"]=asm["dynCall_ii"];var dynCall_viii=Module["dynCall_viii"]=asm["dynCall_viii"];var dynCall_v=Module["dynCall_v"]=asm["dynCall_v"];var dynCall_viid=Module["dynCall_viid"]=asm["dynCall_viid"];var dynCall_iiiii=Module["dynCall_iiiii"]=asm["dynCall_iiiii"];var dynCall_viiiiii=Module["dynCall_viiiiii"]=asm["dynCall_viiiiii"];var dynCall_iii=Module["dynCall_iii"]=asm["dynCall_iii"];var dynCall_viiii=Module["dynCall_viiii"]=asm["dynCall_viiii"];Runtime.stackAlloc=asm["stackAlloc"];Runtime.stackSave=asm["stackSave"];Runtime.stackRestore=asm["stackRestore"];Runtime.establishStackSpace=asm["establishStackSpace"];Runtime.setTempRet0=asm["setTempRet0"];Runtime.getTempRet0=asm["getTempRet0"];function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var initialStackTop;var preloadStartTime=null;var calledMain=false;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};Module["callMain"]=Module.callMain=function callMain(args){assert(runDependencies==0,"cannot call main when async dependencies remain! (listen on __ATMAIN__)");assert(__ATPRERUN__.length==0,"cannot call main when preRun functions remain to be called");args=args||[];ensureInitRuntime();var argc=args.length+1;function pad(){for(var i=0;i<4-1;i++){argv.push(0)}}var argv=[allocate(intArrayFromString(Module["thisProgram"]),"i8",ALLOC_NORMAL)];pad();for(var i=0;i<argc-1;i=i+1){argv.push(allocate(intArrayFromString(args[i]),"i8",ALLOC_NORMAL));pad()}argv.push(0);argv=allocate(argv,"i32",ALLOC_NORMAL);try{var ret=Module["_main"](argc,argv,0);exit(ret,true)}catch(e){if(e instanceof ExitStatus){return}else if(e=="SimulateInfiniteLoop"){Module["noExitRuntime"]=true;return}else{if(e&&typeof e==="object"&&e.stack)Module.printErr("exception thrown: "+[e,e.stack]);throw e}}finally{calledMain=true}};function run(args){args=args||Module["arguments"];if(preloadStartTime===null)preloadStartTime=Date.now();if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();if(Module["_main"]&&shouldRunNow)Module["callMain"](args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout((function(){setTimeout((function(){Module["setStatus"]("")}),1);doRun()}),1)}else{doRun()}}Module["run"]=Module.run=run;function exit(status,implicit){if(implicit&&Module["noExitRuntime"]){return}if(Module["noExitRuntime"]){}else{ABORT=true;EXITSTATUS=status;STACKTOP=initialStackTop;exitRuntime();if(Module["onExit"])Module["onExit"](status)}if(ENVIRONMENT_IS_NODE){process["stdout"]["once"]("drain",(function(){process["exit"](status)}));console.log(" ");setTimeout((function(){process["exit"](status)}),500)}else if(ENVIRONMENT_IS_SHELL&&typeof quit==="function"){quit(status)}throw new ExitStatus(status)}Module["exit"]=Module.exit=exit;var abortDecorators=[];function abort(what){if(what!==undefined){Module.print(what);Module.printErr(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;var extra="\nIf this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.";var output="abort("+what+") at "+stackTrace()+extra;if(abortDecorators){abortDecorators.forEach((function(decorator){output=decorator(output,what)}))}throw output}Module["abort"]=Module.abort=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}var shouldRunNow=true;if(Module["noInitialRun"]){shouldRunNow=false}run()
     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
  20 | ;(function() {
  21 |  'use strict'
  22 | 
    at Parser._raise (/webpack-demo/node_modules/@babel/parser/lib/index.js:742:17)
    at Parser.raiseWithData (/webpack-demo/node_modules/@babel/parser/lib/index.js:735:17)
    at Parser.raise (/webpack-demo/node_modules/@babel/parser/lib/index.js:729:17)
    at ScopeHandler.checkRedeclarationInScope (/webpack-demo/node_modules/@babel/parser/lib/index.js:4769:12)
    at ScopeHandler.declareName (/webpack-demo/node_modules/@babel/parser/lib/index.js:4749:14)
    at Parser.checkLVal (/webpack-demo/node_modules/@babel/parser/lib/index.js:9207:22)
    at Parser.parseVarId (/webpack-demo/node_modules/@babel/parser/lib/index.js:11762:10)
    at Parser.parseVar (/webpack-demo/node_modules/@babel/parser/lib/index.js:11737:12)
    at Parser.parseVarStatement (/webpack-demo/node_modules/@babel/parser/lib/index.js:11549:10)
    at Parser.parseStatementContent (/webpack-demo/node_modules/@babel/parser/lib/index.js:11148:21)
 @ ./src/main.js 4:0-42
ℹ 「wdm」: Failed to compile.
./src/AR.js-master/three.js/build/AR.js中的
错误
模块构建失败(来自./node_modules/babel loader/lib/index.js):
SyntaxError:/webpack demo/src/AR.js-master/three.js/build/AR.js:标识符“\u malloc”已经声明(19:519)
17 | 
18 |//EMSCRIPTEN_END_ASM
>19 |(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var i64Subtract=模块[“i64Subtract”]=asm[“i64Subtract”];var\uuuuu GLOBAL\uuuu sub\u I\u bind\u cpp=模块[“\uuuuu GLOBAL\uuuuu sub\u I\u bind\u cpp”]=asm[“\uuuuu GLOBAL\uuuuu sub\u I\u bind\u cpp”];var fflush=模块[“fflush”]=asm[“fflush”];var\uuuuu GLOBAL\uuuu sub\u ARToolKitJS\u cpp=模块[“\uuuuu GLOBAL\uuuuSub\u ARToolKitJS\u cpp”]=asm[“\uuuuu GLOBAL\uuuu sub\u ARToolKitJS\u cpp”];变量i64Add=Module[“\i64Add”]=asm[“\i64Add”];var _memset=Module[“_memset”]=asm[“_memset”];var runPostSets=Module[“runPostSets”]=asm[“runPostSets”];var _malloc=模块[“_malloc”]=asm[“_malloc”];var _memcpy=模块[“_memcpy”]=asm[“_memcpy”];var\uuuuu getTypeName=Module[“\uuuuuu getTypeName”]=asm[“\uuuuu getTypeName”];var _bitshift64Lshr=模块[“_bitshift64Lshr”]=asm[“_bitshift64Lshr”];var _free=模块[“_free”]=asm[“_free”];var\uuuuuuu errno\u location=模块[“\uuuuuu errno\u location”]=asm[“\uuuuuuu errno\u location”];var _bitshift64Shl=模块[“_bitshift64Shl”]=asm[“_bitshift64Shl”];var dynCall_iiii=模块[“dynCall_iiii”]=asm[“dynCall_iiii”];var dynCall_viiiii=模块[“dynCall_viiiii”]=asm[“dynCall_viiiii”];var dynCall_dii=模块[“dynCall_dii”]=asm[“dynCall_dii”];var dynCall_vid=模块[“dynCall_vid”]=asm[“dynCall_vid”];var dynCall_di=模块[“dynCall_di”]=asm[“dynCall_di”];var dynCall_i=模块[“dynCall_i”]=asm[“dynCall_i”];var dynCall_vi=模块[“dynCall_vi”]=asm[“dynCall_vi”];var dynCall_vii=模块[“dynCall_vii”]=asm[“dynCall_vii”];var dynCall_ii=模块[“dynCall_ii”]=asm[“dynCall_ii”];var dynCall_viii=模块[“dynCall_viii”]=asm[“dynCall_viii”];var dynCall_v=模块[“dynCall_v”]=asm[“dynCall_v”];var dynCall_viid=模块[“dynCall_viid”]=asm[“dynCall_viid”];var dynCall_uiiii=模块[“dynCall_iiii”]=asm[“dynCall_iiiii”];var dynCall_viiiiii=模块[“dynCall_viiiiii”]=asm[“dynCall_viiiiii”];var dynCall_iii=模块[“dynCall_iii”]=asm[“dynCall_iii”];var dynCall_viiii=模块[“dynCall_viiii”]=asm[“dynCall_viiii”];Runtime.stackAlloc=asm[“stackAlloc”];Runtime.stackSave=asm[“stackSave”];Runtime.stackRestore=asm[“stackRestore”];Runtime.EstablistStackSpace=asm[“EstablistStackSpace”];Runtime.setTempRet0=asm[“setTempRet0”];Runtime.getTempRet0=asm[“getTempRet0”];函数ExitStatus(status){this.name=“ExitStatus”;this.message=“程序终止于退出(“+status+”);this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var初始化堆栈顶部;var-preload-starttime=null;var calledMain=false;DependenciesCompleted=函数runCaller(){if(!Module[“calledRun”])run();if(!Module[“calledRun”])DependenciesCompleted=runCaller};Module[“callMain”]=Module.callMain=function callMain(args){assert(runDependencies==0,“在异步依赖项仍然存在时无法调用main!”(侦听uuu ATMAIN_uuu)”;assert(uuu ATPRERUN_uu.length==0,“在预运行函数仍然需要调用时无法调用main”);args=args | |[];ensureInitRuntime();var argc=args.length+1;function pad(){for(var i=0;i0)返回;如果(Module[“calledRun”])返回;函数doRun(){if(Module[“calledRun”])返回;Module[“calledRun”]=true;if(ABORT)返回;insureInRuntime();preMain();if(Module[“onRuntimeInitialized”])Module[“onRuntimeInitialized”]();if(Module[“"main”]&&shouldrunow)Module[“callMain”](args);postRun()}if(Module[“setStatus”]{Module[“setStatus”])(“Running…”)超时((function(){setTimeout((function(){Module[“setStatus”](“”)),1;doRun()),1)}其他{doRun()}模块[“run”]=Module.run=run;函数退出(状态,隐式){if(隐式和模块[“noExitRuntime”]){if(模块[“noExitRuntime”]){否则{ABORT=true;EXITSTATUS=status;STACKTOP=initialStackTop=initialStackTop;exitrutime();if(模块“onExit”]Module status[](环境是节点){process[“stdout”][“once”](“drain”,(function(){process[“exit”](status)});console.log(“”);setTimeout((function(){process[“exit”](status)}),500)}else if(环境是SHELL&&typeof quit==“function”){quit(status)}抛出新的ExitStatus(status)}模块[“exit”]=Module exit=exit=exit;var abortecorators=[];函数中止(what){if){(what!==undefined){Module.print(what);Module.printErr(what);what=JSON.stringify(what)}否则{what=”“}ABORT=true;EXITSTATUS=1;var extra=“\n如果此ABORT()是意外的,则使用-s断言=1进行构建,该断言可以提供更多信息。“+stackTrace()+extra;if(abortDecorators){abortDecorators.forEach((函数(decorator){output=decorator(output,what)}}抛出output}模块[“abort”]=Module.abort=abort;if(模块[“preInit”]){if(模块的类型[“preInit”]=“函数”)模块[“preInit”]=[模块[“preInit”]];while(模块[“preInit”]。长度>0){模块[“preInit”]。pop()}var shouldRunNow=true;if(模块[“noInitialRun”]{shouldRunNow=false}
|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
20 |(函数(){
21 |“严格使用”
22 | 
在Parser._raise(/webpack demo/node_modules/@babel/Parser/lib/index.js:742:17)
在Parser.raiseWithData(/we