gpt4 book ai didi

javascript - webpack 4 - 模块解析失败 : Unexpected character '�' (1:0) on simple JS file

转载 作者:行者123 更新时间:2023-11-30 14:23:24 25 4
gpt4 key购买 nike

于是做了一些简单的webpack学习。按照本教程进行操作:https://www.valentinog.com/blog/webpack-tutorial/

目前只是试图通过运行 npm run build 将 .src/index.js 构建到 ./dist/main.js

./src文件夹下除了index.js没有别的了,./src/index.js的全部内容都是

window.console.log('hello world');

我在控制台中收到此错误。

Hash: 61965fd874c7fad84f98
Version: webpack 4.19.0
Time: 76ms
Built at: 09/16/2018 4:37:31 PM
1 asset
Entrypoint main = main.js
[0] ./src/index.js 177 bytes {0} [built] [failed] [1 error]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production'
for this value. Set 'mode' option to 'development' or 'production' to enable
defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more:
https://webpack.js.org/concepts/mode/

ERROR in ./src/index.js 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)

这不会构建包。

然而,当 ./src/index.js 的内容为空且完全为空时,它构建良好

在上述条件下构建时main.js的内容:

!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l :!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d= function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!= typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){ if(1&t&&(e=r(e)),8&t)返回 e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n), Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};返回 r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0) }([函数(e,t){}]);

我现在有点困惑,webpack 不应该需要一个特殊的加载器来加载常规 js 是我对它如何工作的理解。

额外信息
node -v: 10.4.1 (使用 nvm 管理)
npm -v: 6.1.0
网络包:^4.19.0
webpack-cli: ^3.1.0

最佳答案

错误似乎是注释中提到的字节顺序标记 (bom) Phil。当我尝试此修复时已解决:https://unix.stackexchange.com/questions/381230/how-can-i-remove-the-bom-from-a-utf-8-file在 index.js 上,然后再次构建。

关于javascript - webpack 4 - 模块解析失败 : Unexpected character '�' (1:0) on simple JS file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52351727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com