我正在尝试用装饰器构建JS反应项目.我的.babelrc看起来像这样:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-object-assign",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
Run Code Online (Sandbox Code Playgroud)
添加@ babel/plugin-proposal-decorators问题再次出现.
我使用babel 7,webpack 4并做出反应16.5
webpack.config.js:
const path = require("path");
const webpack = require("webpack");
const componentName = "reports-desktop";
const publicFolderRelativePath = "../../../../../../public/js";
const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
module.exports = {
entry: './reports-desktop.js'
,
output: {
path: path.resolve(__dirname, publicFolderRelativePath),
filename: `${componentName}.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader" …
Run Code Online (Sandbox Code Playgroud) 我想将我的反应应用程序压缩成gzip,实际上它是2.2 MB因此我使用了压缩webpack-plugin但我无法压缩
我的webpack.config.js
const webpack = require('webpack');
const path = require('path');
const fs = require("fs")
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionPlugin = require('compression-webpack-plugin');
const VENDOR_LIBS =[
'antd','axios','moment','rc-time-picker','react',
'react-dom','react-ga','react-google-maps','react-loadable',
'react-redux','react-router','react-router-dom','recompose','redux','redux-thunk'
]
module.exports = (env) => {
const isProduction = env === 'production';
const CSSExtract = new ExtractTextPlugin('styles.css');
return {
node: {
fs: 'empty',
child_process: 'empty',
},
entry: {
bundle:'./src/app.js',
vendor:VENDOR_LIBS
},
output: {
path: path.join(__dirname, 'public'),
filename: '[name].js'
},
module: …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个节点模块,我必须检查用户是否安装了特定的包(这是我必须遵循的逻辑),如果没有,则使用child_process.exec
.
这就是问题出现的地方,即使我的脚本安装了该包(node_modules
也包含它package.json
),如果我require.resolve
再次调用,它会说该模块不存在。
对于我发现的(来自node github问题),node有一种“缓存”,在第一次调用时,如果未安装该包,则该包的缓存条目设置为一个随机值,该值不是路径到它。然后,当您安装并尝试再次调用它时,它会调用该缓存条目。
有没有其他方法可以检查软件包是否已安装,或者我的本地节点安装是否已损坏?
在尝试与 webpack 一起使用时,我遇到了此错误。
我的 webpack 配置是:
const path = require("path");
const webpack = require('webpack');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const nodeFallbacks = require("./nodeFallbacks");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const cwd = process.cwd();
const outputPath = path.join(cwd, "build");
module.exports = {
mode: "development",
devtool: "cheap-module-source-map",
context: path.resolve(cwd, "./"),
entry: {
main: "./src/index.js"
},
output: {
path: outputPath,
publicPath: "/",
pathinfo: false,
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".mjs"],
fallback: {
...nodeFallbacks,
},
},
module: { …
Run Code Online (Sandbox Code Playgroud) 我有一个库,在导出接口的文件之一中:
export interface MyInterface {
...
}
Run Code Online (Sandbox Code Playgroud)
并且有一个默认导出,它是一个react组件。
在index.ts
文件上,我导入了一些东西,然后将它们重新导出:
import Something from "./Something";
import OtherStuff from "./OtherStuff";
import ExportDefault, { MyInterface } from "./QuestionFile";
export { Something, OtherStuff, ExportDefault, MyInterface };
Run Code Online (Sandbox Code Playgroud)
编译时出现错误:
MyInterface不是由QuestionFile导出的。
我的目标是,无论谁导入我的库,也能够导入该类型定义以供使用。
有更好的方法吗?
如果我做:
export * from "./QuestionFile"
它有效,否则会破坏我的构建。
可以在此存储库中找到有关发生情况的示例:https : //github.com/PlayMa256/typescript-babel-error
我正在从babel 6升级到babel 7的过程中,一些使用chai,sinon和酶的旧测试出现以下错误:
TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Run Code Online (Sandbox Code Playgroud)
我确实有一些使用“ require”而不是“ export”的代码,并且我知道babel 7文档说您可能需要使用“ require()。default”。但这似乎并没有帮助(或者我只需要完成将默认值放到任何地方并在错误消失之前调用它们)。还有其他人对此问题有经验吗?
let a;
a = 5;
a = "hi";
Run Code Online (Sandbox Code Playgroud)
为什么这是有效的 TypeScript 代码?除了 «a:number» 之外,还有其他更严格的设置吗?如果不是,那么使用 TypeScipt 有什么意义,如果您可以使用 JavaScript + vscode //@ts-check?我的 tsconfig.json:
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es6",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": false,
"strict": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
},
Run Code Online (Sandbox Code Playgroud) javascript ×3
babel ×2
babeljs ×2
typescript ×2
webpack ×2
aframe ×1
android ×1
compression ×1
ecmascript-6 ×1
gzip ×1
node-modules ×1
node.js ×1
react-native ×1
reactjs ×1
rollup ×1
types ×1