我有一个名为api_path.js的文件名,在其中我有这个
export {
api_path: 'https://localhost:3001/'
}
然后在我的组件中
import { api_path } from 'config/api_path'
我收到了错误:
意外令牌,您可能需要一个合适的加载器来处理这个问题 文件类型。
我需要什么样的装载机?
答案 0 :(得分:0)
The export
keyword is not followed by an object, but a special syntax that lists the identifiers that should be exported.
You have to define a variable that you want to export.
const api_path = 'https://localhost:3001/'
export { api_path }
You can achieve the same by putting the export
keyword before the variable declaration.
export const api_path = 'https://localhost:3001/'
There is no loader needed, because webpack 2+ handles ES modules. The error message only suggests that you may need an appropriate loader, because that wasn't valid ES module syntax but it might have been possible that you were using a special syntax on purpose and forgot to configure a loader for it (a common mistake when including another file type, like CSS).