javascript - 发生构建错误 ReferenceError: describe is not defined > 在 now.sh 部署期间
问题描述
我正在使用now.sh来部署我的nextjs (React) 应用程序。由于此错误,构建失败:
Build error occurred
ReferenceError: describe is not defined
不知道为什么会这样,这是我的.babelrc
{
"env": {
"development": {
"compact": false,
"presets": [
"next/babel",
"@zeit/next-typescript/babel"
],
"plugins": [
["styled-components", {"ssr": true, "displayName": true}],
["@babel/plugin-proposal-decorators", {"legacy": true}]
]
},
"production": {
"presets": [
"next/babel",
"@zeit/next-typescript/babel"
],
"plugins": [
["styled-components", {"ssr": true, "displayName": true}],
["@babel/plugin-proposal-decorators", {"legacy": true}]
]
},
"test": {
"compact": false,
"presets": [
"@babel/preset-typescript",
["next/babel", {"preset-env": { "modules": "commonjs" }}]
],
"plugins": [
["styled-components", { "ssr": true, "displayName": true }],
["@babel/plugin-proposal-decorators", { "legacy": true }],
["babel-plugin-sass-vars"]
]
}
}
}
包.json
"engines" : {
"node" : ">=8.10.0 <11.0.0"
},
"scripts": {
"dev": "NODE_ENV=development next -p 7777",
"build": "NODE_ENV=production next build",
"start": "next -p 7777",
"test": "NODE_ENV=test jest --no-cache",
"test-watch": "NODE_ENV=test jest --watch --no-cache",
"coverage": "NODE_ENV=test jest --coverage",
"update-snap": "NODE_ENV=test jest --updateSnapshot"
},
完整日志:
running "npm run now-build"
> moon.holdings@2.0.0 now-build /tmp/7418164
> next build
Creating an optimized production build ...
> Using external babel configuration
> Location: "/tmp/7418164/.babelrc"
> Build error occurred
ReferenceError: describe is not defined
at Module.kAI8 (/tmp/7418164/.next/serverless/pages/__tests__/about.test.js:63996:1)
at __webpack_require__ (/tmp/7418164/.next/serverless/pages/__tests__/about.test.js:23:31)
at module.exports.+3sd.exports.__esModule (/tmp/7418164/.next/serverless/pages/__tests__/about.test.js:91:18)
at Object.<anonymous> (/tmp/7418164/.next/serverless/pages/__tests__/about.test.js:94:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
npm
ERR! code ELIFECYCLE
使用 describe 的第一个测试:
import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import About from '../about.tsx'
describe('<About /> component', () => {
describe('rendering', () => {
const wrapper = shallow(<About />);
it('should render a component matching the snapshot', () => {
const tree = toJson(wrapper);
expect(tree).toMatchSnapshot();
expect(wrapper).toHaveLength(1);
expect(wrapper.contains(<About/>));
});
});
});
下一个.config
module.exports = (phase, { defaultConfig }) => {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader'
}
]
}
// Note: Nextjs provides webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
return config
}
// ✅ Put the require call here.
const withTypescript = require('@zeit/next-typescript')
const withCSS = require('@zeit/next-sass')
// withCSS({target: 'serverless'})
return withTypescript(withCSS({
webpack(config, options) {
return config
}
}))
}
解决方案
我删除了覆盖该/pages
目录的测试。NextJS 使用页面进行路由。不知道为什么会导致问题,运行覆盖并且看起来页面没有必要覆盖。
希望 NextJS / Now.sh 团队的某个人提供更好的答案,我会选择它。
推荐阅读
- android - 外部原生构建问题、构建命令失败、使用参数 {-HF 执行“C:/User/user.../cmake.exe”时出错
- apache-kafka - Kafka Zookeeper 的用途
- android - 如何更新从 ADB android studio 生成的具有相同密钥存储的 APK 的 Play 商店下载的 APK
- node.js - express 和 CORS 的问题
- python-3.x - Splitting HSV mask into multiple rectangles
- go - go中如何使用runtime.Object创建CRD泛型函数
- javascript - 使用捕获的匹配作为键,用正则表达式替换字符串
- elasticsearch - 启动 ELASTICSEARCH 时,Elasticsearch 进程的最大文件描述符 [4096] 太低
- docker - Docker 应用程序中的 GUI
- c++ - 是否可以在 C++ 中转到更高级别的范围条件?