我最近想出了一個在 Node.js 上運行的新純 JS Web 應用程式(不匯入任何關于 TypeScript 的內容),將 [email protected] 作為框架,[email protected] 作為 Azure SQL 服務器的 ORM 層.
一切正常,我已成功連接到 SQL 服務器。
但是,我不小心洗掉package.json了它而沒有提交。無論如何,我設法重新安裝了丟失的包typeorm,reflect-metadata和mssql. 但是重新安裝后,當我啟動開發服務器時,我遇到了一個我從未見過的新錯誤。
error - ./node_modules/typeorm/browser/index.js
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (3: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
| /*!
| */
> import "reflect-metadata";
| // -------------------------------------------------------------------------
| // Commonly Used exports
我搜索了一下,發現它可能與 webpack 有關。但我對此沒有太多線索。下面是我的next.config.js順便說一句。
module.exports = {
reactStrictMode: true,
webpack: (config, options) => {
config.module.rules.push({
test: /\.html$/i,
loader: "html-loader",
});
return config;
},
};
我嘗試了一些基本的健全性檢查,例如洗掉node_modules/并重新安裝,但沒有運氣。有沒有人知道發生了什么以及如何解決它?
更新:
在@hej 和GitHub 上的這個問題的幫助下,我將這部分添加到我的next.config.js并且它有效!
config.module.rules.push({
test: /\.[jt]sx?$/,
include: [/node_modules(.*[/\\]) typeorm/],
type: "javascript/auto",
use: "babel-loader",
});
uj5u.com熱心網友回復:
嘗試將此添加到您的 webpack 配置中:
{
module: {
rules: [
{
test: /\.[jt]sx?$/,
include: [/node_modules(.*[/\\]) typeorm/],
use: "babel-loader",
},
],
},
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/429158.html
