serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 414 forks source link

Error: Non-whitespace before first tag #466

Open shivamsk opened 5 years ago

shivamsk commented 5 years ago

This is a Bug Report

Description

Found this error when packaging (sls package ) Installed the xml-loader to include the xml file in the package . Added the file GetAvailabilityManifest.xml it in src/handler/abc/ and imported it in src/handler/KinesisHandler.js as

import xmlFile from './abc/GetAvailabilityManifest.xml';

Took the xml-loader usage reference from here: https://webpack.js.org/guides/asset-management/#loading-data

For bug reports:

module.exports = { entry: slsw.lib.entries, output: { libraryTarget: 'commonjs2', path: path.join(dirname, '.webpack'), filename: '[name].js', sourceMapFilename: '[file].map', }, module: { rules: [ { test: /.js$/, loader: 'babel-loader', include: [path.join(dirname, 'src')], }, { test: /.json$/, loader: 'json', include: path.join(dirname, 'src'), }, { test: /.xml$/, loader: 'xml-loader', include: path.join(dirname, 'src'), }, ], }, externals: ['aws-sdk', nodeExternals()], devtool: 'nosources-source-map', target: 'node', node: { __dirname: false, }, mode: slsw.lib.webpack.isLocal ? 'development' : 'production', optimization: { // We no not want to minimize our code. minimize: false, }, performance: { // Turn off size warnings for entry points hints: false, },

};


package.json 
"serverless-webpack": "^5.2.0",
"webpack": "^4.2.0",
"webpack-node-externals": "^1.7.2",
"xml-loader": "^1.2.1"

* What stacktrace or error message from your provider did you see?

ROR in ./src/handler/abc/GetAvailabilityManifest.xml Module build failed (from ./node_modules/xml-loader/index.js): Error: Non-whitespace before first tag. Line: 0 Column: 1 Char: � at error (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/sax/lib/sax.js:667:10) at strictFail (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/sax/lib/sax.js:693:7) at beginWhiteSpace (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/sax/lib/sax.js:967:7) at SAXParser.write (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/sax/lib/sax.js:1019:11) at Parser.exports.Parser.Parser.parseString (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/xml2js/lib/parser.js:322:31) at Parser.parseString (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/xml2js/lib/parser.js:5:59) at exports.parseString (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/xml2js/lib/parser.js:354:19) at Object.module.exports (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/xml-loader/index.js:26:3) @ ./src/handler/KinesisHandler.js 106:31-75

ERROR in ./src/handler/KinesisHandler.js Module not found: Error: Can't resolve 'xml' in '/Users/siva_krishna/Desktop/TestProjects/abcd-integration/src/handler' BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders. You need to specify 'xml-loader' instead of 'xml', see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed @ ./src/handler/KinesisHandler.js 122:11-59

Error --------------------------------------------------

Webpack compilation error, see above

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Stack Trace --------------------------------------------

Error: Webpack compilation error, see above at _.forEach.compileStats (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/serverless-webpack/lib/compile.js:34:19) at arrayEach (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/lodash/lodash.js:516:11) at Function.forEach (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/lodash/lodash.js:9344:14) at BbPromise.fromCallback.then.stats (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/serverless-webpack/lib/compile.js:30:11) at finalCallback (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:210:39) at hooks.done.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:226:13) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at onCompiled (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:224:21) at hooks.afterCompile.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:552:14) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at compilation.seal.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:549:30) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at hooks.optimizeAssets.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1323:35) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at hooks.optimizeChunkAssets.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1314:32) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at hooks.additionalAssets.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1309:36) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at hooks.optimizeTree.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1305:32) at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/Hook.js:154:20) at Compilation.seal (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1242:27) at hooks.make.callAsync.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compiler.js:546:17) at _done (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :9:1) at _err1 (eval at create (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/tapable/lib/HookCodeFactory.js:32:10), :32:22) at _addModuleChain (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1093:12) at processModuleDependencies.err (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/webpack/lib/Compilation.js:1005:9) at process.internalTickCallback (internal/process/next_tick.js:70:11) From previous event: at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:390:22) at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:408:17) at ServerlessWebpack.BbPromise.bind.then.then (/Users/siva_krishna/Desktop/TestProjects/abcd-integration/node_modules/serverless-webpack/index.js:101:51) at processImmediate (timers.js:632:19) at process.topLevelDomainCallback (domain.js:120:23)

Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Issues: forum.serverless.com

Your Environment Information ----------------------------- OS: darwin Node Version: 11.1.0 Serverless Version: 1.32.0



## Additional Data

* ***Serverless-Webpack Version you're using***:  5.2.0 
* ***Webpack version you're using***: 4.2.0
* ***Serverless Framework Version you're using***: 1.32.0
* ***Operating System***:
Mac OS Sierra
HyperBrain commented 5 years ago

@shivamsk Thanks for reporting.

Did you check if a plain webpack compile also yields the issue? The issue looks more like something with webpack itself went wrong.