簡體   English   中英

Node.js編譯我不需要的文件。 它是如何工作的?

[英]Node.js compiles files I did not require. How does that work under the hood?

我在node.js中遇到無法理解的錯誤。 我有一個我根本不需要的文件,但是在模塊系統加載和編譯中找到了我不希望的文件,因為它只能在客戶端上使用。

這是使用babel的設置:

bootstrap.js

require('babel/register');
require('./server/index');

index.js與main.jsx沒有任何關系。 不過,這里是其導入的模塊:

index.js

import express from 'express';
import routes from './routes';
import path from 'path';

但是以某種方式,node.js嘗試加載和編譯main.jsx ,這給了我這樣的錯誤:

/home/minheq/Git/react_app/node_modules/react/lib/invariant.js:49
throw error;
^

Error: Invariant Violation: You cannot use <HistoryLocation> without a DOM
at invariant (/home/minheq/Git/react_app/node_modules/react/lib/invariant.js:42:15)
at createRouter (/home/minheq/Git/react_app/node_modules/react-router/lib/createRouter.js:131:5)
at Object.runRouter [as run] (/home/minheq/Git/react_app/node_modules/react-router/lib/runRouter.js:40:16)
at Object.<anonymous> (/home/minheq/Git/react_app/app/main.jsx:6:10)
at Module._compile (module.js:430:26)
at normalLoader (/home/minheq/Git/react_app/node_modules/babel-core/lib/api/register/node.js:199:5)
at Object.require.extensions.(anonymous function) [as .jsx] (/home/minheq/Git/react_app/node_modules/babel-core/lib/api/register/node.js:216:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)

特別是這一行:

at Object.<anonymous> (/home/minheq/Git/react_app/app/main.jsx:6:10)'

關於如何發生的任何參考? 謝謝!

main.jsx的導入來自以下行:

import routes from './routes';

在錯誤堆棧跟蹤中,您將看到以下內容:

react-router/lib/runRouter.js

關於Invariant Violation ,請在Github上看到這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM