导入的常量未定义

我有一个server.js文件和一个main.js文件,与watchify app/src/main.js --node -t babelify -o app/build/main.js & watchify app/src/server.js --node -t babelify -o app/build/server.js

main.js:

 const rnd = 3 export { rnd } 

server.js:

 import { rnd } from '../build/main' console.log(rnd) import express from 'express' let app = express() app.listen(8080) 

但是它undefined日志。 我究竟做错了什么?

main.js构build:

 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rnd = 3; exports.rnd = rnd; },{}]},{},[1]); 

server.js构build:

 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ "use strict"; (function e(t, n, r) { function s(o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);var f = new Error("Cannot find module '" + o + "'");throw f.code = "MODULE_NOT_FOUND", f; }var l = n[o] = { exports: {} };t[o][0].call(l.exports, function (e) { var n = t[o][1][e];return s(n ? n : e); }, l, l.exports, e, t, n, r); }return n[o].exports; }var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) { s(r[o]); }return s; })({ 1: [function (require, module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rnd = 3; exports.rnd = rnd; }, {}] }, {}, [1]); },{}],2:[function(require,module,exports){ 'use strict'; var _main = require('../build/main'); var _express = require('express'); var _express2 = _interopRequireDefault(_express); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } console.log(_main.rnd); var app = (0, _express2.default)(); app.listen(8080); },{"../build/main":1,"express":20}],3:[function(require,module,exports){ // ... 

       

网上收集的解决方案 "导入的常量未定义"