所以我按照这里的安装,但babel需要很长时间来编译,甚至是小文件:
app.js
let app = 1;
Run Code Online (Sandbox Code Playgroud)
.babelrc
{ "presets": ["es2015"] }
Run Code Online (Sandbox Code Playgroud)
的package.json
"scripts": {
"build": "babel app.js -o dist/app.js"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-preset-es2015": "^6.3.13"
}
Run Code Online (Sandbox Code Playgroud)
然后npm run build
需要〜30s才能编译.
我正在使用 npm@3.3.12
我有一个在Node.js和浏览器中使用的内部库.它有许多文件,与Grunt任务和不同的序言连接,一个用于浏览器,一个用于Node:
浏览器:
// dependent 3rd-party libs like Mustache are already global
window.myLib = { /*just a namespace object filled with stuff later*/ }
// then comes the plain javascript which just adds elements to myLib.
// This part is identical to that used in Node
// example:
myLib.renderPartDetail = function (...) {...};
Run Code Online (Sandbox Code Playgroud)
节点:
var Mustache = require('mustache');
var myLib = {};
module.exports = myLib;
// then comes the plain javascript which just adds elements to myLib.
// This part is …
Run Code Online (Sandbox Code Playgroud) 从react-native运行应用程序时,我在模拟器/设备上收到以下错误消息。
** ERROR **
The development server returned response error code: 500
URL: http: //10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false
Body: {
"type": "TransformError",
"lineNumber": 0,
"errors": [{
"description": "/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/App.js: Cannot read property 'bindings' of null",
"lineNumber": 0
}],
"name": "SyntaxError",
"message": "/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/App.js: Cannot read property 'bindings' of null",
"stack": "TypeError: Cannot read property 'bindings' of null\n at Scope.moveBindingTo (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/@babel/traverse/lib/scope/index.js:867:13)\n at BlockScoping.updateScopeInfo (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:364:17)\n at BlockScoping.run (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:330:12)\n at PluginPass.BlockStatementSwitchStatementProgram (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:70:24)\n at newFn (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/@babel/traverse/lib/visitors.js:193:21)\n at NodePath._call (/Users/admin/Documents/PULSE/Phase II/Projects/pulse-mobile-common-rn/node_modules/@babel/traverse/lib/path/context.js:53:20)\n at NodePath.call …
Run Code Online (Sandbox Code Playgroud)我正在通过设置 babel 来处理我的 React 应用程序。不幸的是,在使用 yarn 进行设置和构建bundle.js
文件时,我遇到了一些问题:
ERROR in ./src/app.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '@babel/preset-env' from '/Users/react-file/Desktop/indecision'
at Function.resolveSync [as sync] (/Users/react-file/Desktop/indecision/node_modules/resolve/lib/sync.js:89:15)
at resolveStandardizedName (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
at /Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-chain.js:320:26)
at /Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-chain.js:283:7
at Generator.next (<anonymous>)
at buildRootChain (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/config-chain.js:120:29)
at buildRootChain.next (<anonymous>)
at loadPrivatePartialConfig (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/partial.js:95:62)
at loadPrivatePartialConfig.next (<anonymous>)
at Function.<anonymous> (/Users/react-file/Desktop/indecision/node_modules/@babel/core/lib/config/partial.js:120:25)
at Generator.next …
Run Code Online (Sandbox Code Playgroud) javascript ×3
node.js ×3
babeljs ×2
webpack ×2
browserify ×1
ecmascript-6 ×1
npm ×1
react-native ×1
reactjs ×1
typescript ×1