从未提供所需的命名空间 - ES6模块和关闭

时间:2017-09-02 06:37:37

标签: javascript google-closure-compiler google-closure-library

我在使用Closure编译代码时尝试使用ES6模块。虽然不鼓励,但它似乎得到了支持。

我试图将示例减少到最小,这是我目前的情况。

文件结构

路径C:\...\dw-ng2-app>git add --all warning: LF will be replaced by CRLF in src/app/app.component.html. The file will have its original line endings in your working directory. C:\...\dw-ng2-app>git commit -m "added names" [dev d3749c7] added names 1 file changed, 4 insertions(+) C:\...\dw-ng2-app>git push origin dev Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 482 bytes | 0 bytes/s, done. Total 5 (delta 4), reused 0 (delta 0) remote: remote: Create pull request for dev: remote: https://bitbucket.org/ManuChadha/angularcli/pull-requests/new?source=dev&t=1 remote: To ssh://bitbucket.org/ManuChadha/angularcli.git cddddca..d3749c7 dev -> dev

包含

  • closure.jar
  • 测试/ app.js
  • 测试/ module.js

测试/ module.js

/user/.../myapp/js/

测试/ app.js

const A = function() { return 'Hello, World' };

export { A }

编辑命令

然后,我运行此命令来编译我的代码:

import { A } from '/test/module.js'

const text = A();
console.log(text);

错误

我收到以下错误:

java -jar closure.jar \
  --js test/**.js \
  --js_output_file test/main.js \
  --dependency_mode=STRICT \
  --entry_point test/app.js \
  --language_in ECMASCRIPT6

问题: 为什么会这样?我该如何解决?

谢谢!

导入测试

我尝试了一些导入选项,例如:

test/app.js:1: ERROR - required "module$test$module" namespace never provided
import { A } from '/test/module.js'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

不同的导入会抛出不同的错误,因为它们可能无法检测到该文件。例子:

import { A } from '/test/module.js'
import { A } from 'test/module.js'
import { A } from '/test/module'
import { A } from 'test/module'
import { A } from './module.js'
import { A } from './module'
import { A } from '/module.js'
import { A } from '/module'
import { A } from 'module.js'
import { A } from 'module'

test/app.js:1: WARNING - Failed to load module "/test/module"
import { A } from '/test/module'

导出测试

使用原始导入:

test/app.js:1: WARNING - Invalid module path "test/module.js" for resolution mode "BROWSER"
import { A } from 'test/module.js'

我还使用了一些出口替代品:

import { A } from '/test/module.js'

0 个答案:

没有答案