Error: Unknown named module: "./constants"
Error: Unknown named module: "./constants"
我在尝试将 API,特别是 what3words API 导入我的 React 本机应用程序时遇到问题。问题是每次我尝试导入模块时,都会收到错误 'Unknown named module'
我已经设法查明问题所在。当我进入 node_modules 文件夹,然后转到 what3words/api 文件夹并注释掉所有 'requires' 时,错误消失了,但是我无法使用 api.
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./constants", "./requests/autosuggest", "./requests/autosuggest-selection", "./requests/available-languages", "./requests/convert-to-3wa", "./requests/convert-to-coordinates", "./requests/grid-section", "./utils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.valid3wa = exports.getWords = exports.getOptions = exports.setOptions = exports.gridSectionGeoJson = exports.gridSection = exports.convertToCoordinatesGeoJson = exports.convertToCoordinates = exports.convertTo3waGeoJson = exports.convertTo3wa = exports.availableLanguages = exports.autosuggestSelection = exports.autosuggest = exports.W3W_REGEX = void 0;
var constants_1 = require("./constants");
Object.defineProperty(exports, "W3W_REGEX", { enumerable: true, get: function () { return constants_1.W3W_REGEX; } });
// var autosuggest_1 = require("./requests/autosuggest");
Object.defineProperty(exports, "autosuggest", { enumerable: true, get: function () { return autosuggest_1.autosuggest; } });
// var autosuggest_selection_1 = require("./requests/autosuggest-selection");
Object.defineProperty(exports, "autosuggestSelection", { enumerable: true, get: function () { return autosuggest_selection_1.autosuggestSelection; } });
// var available_languages_1 = require("./requests/available-languages");
Object.defineProperty(exports, "availableLanguages", { enumerable: true, get: function () { return available_languages_1.availableLanguages; } });
// var convert_to_3wa_1 = require("./requests/convert-to-3wa");
Object.defineProperty(exports, "convertTo3wa", { enumerable: true, get: function () { return convert_to_3wa_1.convertTo3wa; } });
Object.defineProperty(exports, "convertTo3waGeoJson", { enumerable: true, get: function () { return convert_to_3wa_1.convertTo3waGeoJson; } });
// var convert_to_coordinates_1 = require("./requests/convert-to-coordinates");
Object.defineProperty(exports, "convertToCoordinates", { enumerable: true, get: function () { return convert_to_coordinates_1.convertToCoordinates; } });
Object.defineProperty(exports, "convertToCoordinatesGeoJson", { enumerable: true, get: function () { return convert_to_coordinates_1.convertToCoordinatesGeoJson; } });
// var grid_section_1 = require("./requests/grid-section");
Object.defineProperty(exports, "gridSection", { enumerable: true, get: function () { return grid_section_1.gridSection; } });
Object.defineProperty(exports, "gridSectionGeoJson", { enumerable: true, get: function () { return grid_section_1.gridSectionGeoJson; } });
// var utils_1 = require("../es2015/utils.js");
Object.defineProperty(exports, "setOptions", { enumerable: true, get: function () { return utils_1.setOptions; } });
Object.defineProperty(exports, "getOptions", { enumerable: true, get: function () { return utils_1.getOptions; } });
Object.defineProperty(exports, "getWords", { enumerable: true, get: function () { return utils_1.getWords; } });
Object.defineProperty(exports, "valid3wa", { enumerable: true, get: function () { return utils_1.valid3wa; } });
});
网上查了一下,好像是metro和require函数的问题。请帮忙,谢谢
设法修复它!!在 what3words api 的一位贡献者的帮助下。这似乎是 metro 无法捆绑 umd 模块的问题。幸运的是,what3words api 有我们可以使用的 es2015 模块,所以我只用了
const api = require('@what3words/api/es2015');
代替之前的
const api = require('@what3words/api');
检查 https://github.com/what3words/w3w-node-wrapper/issues/28 进行完整调试
我在尝试将 API,特别是 what3words API 导入我的 React 本机应用程序时遇到问题。问题是每次我尝试导入模块时,都会收到错误 'Unknown named module'
我已经设法查明问题所在。当我进入 node_modules 文件夹,然后转到 what3words/api 文件夹并注释掉所有 'requires' 时,错误消失了,但是我无法使用 api.
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./constants", "./requests/autosuggest", "./requests/autosuggest-selection", "./requests/available-languages", "./requests/convert-to-3wa", "./requests/convert-to-coordinates", "./requests/grid-section", "./utils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.valid3wa = exports.getWords = exports.getOptions = exports.setOptions = exports.gridSectionGeoJson = exports.gridSection = exports.convertToCoordinatesGeoJson = exports.convertToCoordinates = exports.convertTo3waGeoJson = exports.convertTo3wa = exports.availableLanguages = exports.autosuggestSelection = exports.autosuggest = exports.W3W_REGEX = void 0;
var constants_1 = require("./constants");
Object.defineProperty(exports, "W3W_REGEX", { enumerable: true, get: function () { return constants_1.W3W_REGEX; } });
// var autosuggest_1 = require("./requests/autosuggest");
Object.defineProperty(exports, "autosuggest", { enumerable: true, get: function () { return autosuggest_1.autosuggest; } });
// var autosuggest_selection_1 = require("./requests/autosuggest-selection");
Object.defineProperty(exports, "autosuggestSelection", { enumerable: true, get: function () { return autosuggest_selection_1.autosuggestSelection; } });
// var available_languages_1 = require("./requests/available-languages");
Object.defineProperty(exports, "availableLanguages", { enumerable: true, get: function () { return available_languages_1.availableLanguages; } });
// var convert_to_3wa_1 = require("./requests/convert-to-3wa");
Object.defineProperty(exports, "convertTo3wa", { enumerable: true, get: function () { return convert_to_3wa_1.convertTo3wa; } });
Object.defineProperty(exports, "convertTo3waGeoJson", { enumerable: true, get: function () { return convert_to_3wa_1.convertTo3waGeoJson; } });
// var convert_to_coordinates_1 = require("./requests/convert-to-coordinates");
Object.defineProperty(exports, "convertToCoordinates", { enumerable: true, get: function () { return convert_to_coordinates_1.convertToCoordinates; } });
Object.defineProperty(exports, "convertToCoordinatesGeoJson", { enumerable: true, get: function () { return convert_to_coordinates_1.convertToCoordinatesGeoJson; } });
// var grid_section_1 = require("./requests/grid-section");
Object.defineProperty(exports, "gridSection", { enumerable: true, get: function () { return grid_section_1.gridSection; } });
Object.defineProperty(exports, "gridSectionGeoJson", { enumerable: true, get: function () { return grid_section_1.gridSectionGeoJson; } });
// var utils_1 = require("../es2015/utils.js");
Object.defineProperty(exports, "setOptions", { enumerable: true, get: function () { return utils_1.setOptions; } });
Object.defineProperty(exports, "getOptions", { enumerable: true, get: function () { return utils_1.getOptions; } });
Object.defineProperty(exports, "getWords", { enumerable: true, get: function () { return utils_1.getWords; } });
Object.defineProperty(exports, "valid3wa", { enumerable: true, get: function () { return utils_1.valid3wa; } });
});
网上查了一下,好像是metro和require函数的问题。请帮忙,谢谢
设法修复它!!在 what3words api 的一位贡献者的帮助下。这似乎是 metro 无法捆绑 umd 模块的问题。幸运的是,what3words api 有我们可以使用的 es2015 模块,所以我只用了
const api = require('@what3words/api/es2015');
代替之前的
const api = require('@what3words/api');
检查 https://github.com/what3words/w3w-node-wrapper/issues/28 进行完整调试