首页 > 解决方案 > 打包js文件导入bpmn图时webpack失败

问题描述

我需要捆绑一个js文件。

我的项目文件夹

www/
   src/
     app.js
     resources/
              newDiagram.bpmn

   public/

src/app.js,这条线

import diagramXML from './resources/newDiagram.bpmn';

使捆绑失败并出现以下错误

$ ./node_modules/.bin/webpack ./src/app.js -o public/app.bundled.js --mode development

错误

asset main.js 1.9 MiB [emitted] (name: main)

runtime modules 1.13 KiB 5 modules

orphan modules 40 bytes [orphan] 1 module

modules by path ./node_modules/diagram-js/lib/ 568 KiB 187 modules

modules by path ./node_modules/bpmn-js/lib/ 484 KiB 131 modules

modules by path ./node_modules/diagram-js-direct-editing/ 15.1 KiB 3 modules

modules by path ./node_modules/object-refs/ 7.26 KiB

./node_modules/object-refs/index.js 97 bytes [built] [code generated]

./node_modules/object-refs/lib/refs.js 4.43 KiB [built] [code generated]

./node_modules/object-refs/lib/collection.js 2.74 KiB [built] [code generated]

modules by path ./src/ 4.22 KiB

./src/app.js 3.31 KiB [built] [code generated]

./src/resources/newDiagram.bpmn 932 bytes [built] [code generated] [1 error]

13 modules

ERROR in ./src/resources/newDiagram.bpmn 1:0

Module parse failed: Unexpected token (1:0)

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

> <?xml version="1.0" encoding="UTF-8"?>

| <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn">

| <bpmn2:process id="Process_1" isExecutable="false">

@ ./src/app.js 2:0-53

知道为什么吗?

感谢您提供的任何帮助。

标签: javascriptnode.jswebpack

解决方案


推荐阅读