J'ai une application React et un fichier dans lequel je veux stocker des choses liées à api.Import Webpack à partir de fichiers utilisant module.exports
const proxy = require('http-proxy-middleware');
const path = require('path');
//.....
const targetApi = (objectWithUrlEntries) => {
Object.keys(objectWithUrlEntries).forEach((key) => {
objectWithUrlEntries[key] = path.join('/api/', objectWithUrlEntries[key]);
});
};
module.exports.proxyExpressCalls = proxyExpressCalls;
module.exports.devServerProxyConfig = devServerProxyConfig;
module.exports.targetApi = targetApi;
Certaines de ces choses seront utilisées par webpack lui-même, et certains seront utilisés à l'intérieur de l'application (pour cibler correctement les appels api).
Cependant lorsque je tente d'importer des choses dans mon application:
// @flow
import { buildUrl } from 'data/utils';
import type { Axios } from './flow.types';
import { targetApi } from './api';
console.log(targetApi());
Je reçois des erreurs. Dans le terminal:
AVERTISSEMENT dans ./src/data/redux/api/user.js 6: 12-21 « export 'targetApi' n'a pas été trouvé dans './api'
dans le navigateur.
api.js?d669:39 Uncaught TypeError: Cannot set property 'proxyExpressCalls' of undefined
at Object.eval (api.js?d669:39)
at eval (api.js:60)
at Object../src/data/redux/api/api.js (client.bundle.js:11620)
at __webpack_require__ (client.bundle.js:708)
at fn (client.bundle.js:113)
at eval (user.js:15)
at Object../src/data/redux/api/user.js (client.bundle.js:11668)
at __webpack_require__ (client.bundle.js:708)
at fn (client.bundle.js:113)
at eval (user.js:18)
le problème est que lorsque l'application est empaqueté commonjs
exportations échouent, mais si j'utiliser la syntaxe ES6 export
Node
serait alors l'échec