【问题标题】:iisnode not working with babeliisnode 不使用 babel
【发布时间】:2016-06-18 14:05:19
【问题描述】:

我有这个小服务器,它在 iisnode 上运行良好:

index.js

var express = require('express')

var app = express()
var port = process.env.PORT

app.get('/test/foo', function(req, res) {
  res.send('HALLO WORLD')
})

app.listen(port)

但是,如果我想使用 Babel 并像这样重写我的应用程序:

index.js

require('babel-register')
require('babel-polyfill')
require('./server')

server.js

import express from 'express'

const app = express()
const port = process.env.PORT

app.get('/test/foo', (req, res) => {
  res.send('HALLO WORLD')
})

app.listen(port)

现在,如果我导航到 localhost/test/foo,我会收到以下错误消息:

Application has thrown an uncaught exception and is terminated:
Error: EEXIST: file already exists, mkdir 'C:\Windows\system32\config\systemprofile'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:916:18)
    at sync (C:\Projects\winAuthTest\node_modules\mkdirp\index.js:71:13)
    at save (C:\Projects\winAuthTest\node_modules\babel-register\lib\cache.js:56:44)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Function.Module.runMain (module.js:577:11)
    at startup (node.js:159:18)
    at node.js:444:3

这是来自etw.bat的日志:

<Events>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{9e814aad-3204-11d2-9a82-006008a86939}" />
        <EventID>0</EventID>
        <Version>2</Version>
        <Level>0</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:06.126498500Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="3272" ThreadID="5704" ProcessorID="0" KernelTime="15" UserTime="0" />
        <Channel />
        <Computer />
    </System>
    <EventData>
        <Data Name="BufferSize">    8192</Data>
        <Data Name="Version">83951626</Data>
        <Data Name="ProviderVersion">   10586</Data>
        <Data Name="NumberOfProcessors">       4</Data>
        <Data Name="EndTime">131107367592610163</Data>
        <Data Name="TimerResolution">  156250</Data>
        <Data Name="MaxFileSize">       0</Data>
        <Data Name="LogFileMode">0x0</Data>
        <Data Name="BuffersWritten">       5</Data>
        <Data Name="StartBuffers">       1</Data>
        <Data Name="PointerSize">       8</Data>
        <Data Name="EventsLost">       0</Data>
        <Data Name="CPUSpeed">    3392</Data>
        <Data Name="LoggerName">0x9</Data>
        <Data Name="LogFileName">0x6</Data>
        <Data Name="BootTime">131107297904974955</Data>
        <Data Name="PerfFreq">3312787</Data>
        <Data Name="StartTime">131107367461264985</Data>
        <Data Name="ReservedFlags">0x1</Data>
        <Data Name="BuffersLost">       0</Data>
        <Data Name="SessionNameString">iisnode</Data>
        <Data Name="LogFileNameString">C:\Users\buina\AppData\Local\Temp\iisnode.etl</Data>
    </EventData>
    <RenderingInfo Culture="lt-LT">
        <Opcode>Header</Opcode>
        <Provider>MSNT_SystemTrace</Provider>
        <EventName xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">EventTrace</EventName>
    </RenderingInfo>
    <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
        <EventGuid>{68fdd900-4a3e-11d1-84f4-0000f80464e3}</EventGuid>
    </ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.406205500Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="0" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>iisnode received a new http request</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.406219400Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="0" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode increases pending async operation count</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.428481900Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="3" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>iisnode initialized a new node.exe process</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.428514200Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="3" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode scheduled a retry of a named pipe connection to the node.exe process </Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.428522700Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="3" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode dispatched new http request</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.428523300Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="3" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode decreases pending async operation count</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.428523900Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="3" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode leaves CNodeHttpModule::OnExecuteRequestHandler with RQ_NOTIFICATION_PENDING</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.679108400Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="2" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode scheduled a retry of a named pipe connection to the node.exe process </Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:09.929845000Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="2" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode scheduled a retry of a named pipe connection to the node.exe process </Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.180069400Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="2" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode scheduled a retry of a named pipe connection to the node.exe process </Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>2</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.282203900Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="9200" ProcessorID="2" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>iisnode detected termination of node.exe process</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>2</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430106300Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="3" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode was unable to establish named pipe connection to the node.exe process before the process terminated</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430108100Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="3" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode request processing failed for reasons unrecognized by iisnode</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430355600Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="3" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode decreases pending async operation count</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430356500Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="8060" ProcessorID="3" KernelTime="0" UserTime="0" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode posts completion from SendEmtpyResponse</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430413900Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="1" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode increases pending async operation count</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430414800Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="1" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode enters CNodeHttpModule::OnAsyncCompletion callback</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430415400Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="1" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode decreases pending async operation count</Data>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Guid="{1040dfc4-61db-484a-9530-584b2735f7f7}" />
        <EventID>0</EventID>
        <Version>0</Version>
        <Level>5</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x0</Keywords>
        <TimeCreated SystemTime="2016-06-18T18:19:10.430416000Z" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessID="1020" ThreadID="10636" ProcessorID="1" KernelTime="0" UserTime="15" />
        <Channel />
        <Computer />
    </System>
        <Data>{B731012E-2C0B-48E5-BDE6-D78B4C16C484}: iisnode leaves CNodeHttpModule::OnAsyncCompletion with RQ_NOTIFICATION_FINISH_REQUEST</Data>
</Event>
</Events>

如果我从应用程序文件夹中的命令行运行node index.js,以下代码可以正常工作。

为了让我想要的用 Babel 编写的应用程序在 iisnode 上运行,我需要修改什么?

【问题讨论】:

  • 如果您在开发时发现任何不需要编译步骤的好解决方法,请告诉我。我将求助于直接在节点上运行 Web 服务器 :(
  • 这个 repo github.com/lancetw/react-isomorphic-bundle 似乎正在使用 iisnode 和 babel-core/register。没有足够的时间来研究它,但是一旦我有空闲时间,我会检查一下。
  • 看起来他们在做同样的事情。他们使用 nodemon 在 dev 模式下运行 Node.js,而 web.config 用于生产使用已编译的文件(在 ./lib 中)
  • 检查问题跟踪器,有人发布了更好的解决方法。看来是 babel-register 的缓存有问题

标签: javascript babeljs iisnode


【解决方案1】:

这似乎是 iisnode 和 babel-register 中的错误。如果你手动编译它就可以了。

我同时提交了一个错误:https://github.com/tjanczuk/iisnode/issues/518

编辑:由 matterker 在问题跟踪器上发布的更好的解决方法:

对于开发,您可以使用 web.config 中的应用配置设置禁用缓存:

<configuration>
  <appSettings>
    <add key="BABEL_DISABLE_CACHE" value="true" />
  </appSettings>
  [...]
</configuration>

此外,如果在生产环境中使用 babel/register,您还可以更改缓存位置: https://babeljs.io/docs/usage/require/#environment-variables

【讨论】:

    【解决方案2】:

    就像@user120242 指出的那样,这是 Babel 缓存的问题。我以这种方式修改了我的web.config 文件:

    <configuration>
      <appSettings>
        <add key="BABEL_CACHE_PATH" value="C:\Babel\cache.json" />
      </appSettings>
      <system.webServer>
        <iisnode promoteServerVars="LOGON_USER" />
        <handlers>
          <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
          <rules>
            <rule name="test">
              <match url="/*" />
              <action type="Rewrite" url="index.js" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    现在它工作得很好。

    【讨论】:

    • 还需要什么其他配置?我目前正在尝试执行此操作,但无法让服务器停止抱怨您的原始问题。
    • @Austin 对不起,伙计,已经两年了,这是一个玩具项目。想不起来了?
    猜你喜欢
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多